html52.com
我爱小程序-开发者交流社区

云数据库文档不严谨?

云数据库文档不严谨啊,发现了好多处

新功能,让新手如何适应啊

毕竟是跟着例子走呢

1、Aggregate.bucket(object: Object): Aggregate

https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.bucket.html#%E7%A4%BA%E4%BE%8B

output: {
  count: $.sum(1),
  ...
  <outputN>: <accumulator expr>
}

但在官方程序例中,却写成

db.collection('items').aggregate()
  .bucket({
    groupBy: '$price',
    boundaries: [0, 50, 100],
    default: 'other',
    output: {
      count: $.sum(),
      ids: $.push('$_id')
    }
  })
  .end()

返回结果如下:

 [
  {
    "_id": 0,
    "count": 2,
    "ids": [
      "1",
      "3"
    ]
  },
  {
    "_id": 50,
    "count": 2,
    "ids": [
      "2",
      "4"
    ]
  },
  {
    "_id": "other",
    "count": 22,
    "ids": [
      "5"
    ]
  }
]

敢问最后是如何计算count成22的呢? 明明只有1个啊


2、Aggregate.bucket(object: Object): Aggregate

https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.bucket.html#%E7%A4%BA%E4%BE%8B

output: {
  count: $.sum(1),
  ...
  <outputN>: <accumulator expr>
}

但在官方程序例中,却写成

db.collection('items').aggregate()
  .bucket({
    groupBy: '$price',
    boundaries: [0, 50, 100],
    default: 'other',
    output: {
      count: $.sum(),
      ids: $.push('$_id')
    }
  })
  .end()

返回结果如下:

 [
  {
    "_id": 0,
    "count": 2,
    "ids": [
      "1",
      "3"
    ]
  },
  {
    "_id": 50,
    "count": 2,
    "ids": [
      "2",
      "4"
    ]
  },
  {
    "_id": "other",
    "count": 22,
    "ids": [
      "5"
    ]
  }
]

问题跟前面是一样的,我想知道错误的文档是怎么复制粘贴的呢(o(* ̄︶ ̄*)o)


3、 Aggregate.bucketAuto(object: Object): Aggregate

https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/aggregate/Aggregate.bucketAuto.html#%E7%A4%BA%E4%BE%8B

db.collection('items').aggregate()
  .bucket({
    groupBy: '$price',
    buckets: 3,
  })
  .end()

为什么例子的API变成了bucket呢,这是不对的,需要改成bucketAuto


4、其他还在学习中,拜托再认真核对下吧,谢谢!!!

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付