云数据库文档不严谨啊,发现了好多处
新功能,让新手如何适应啊
毕竟是跟着例子走呢
1、Aggregate.bucket(object: Object): Aggregate
output: {
count: $.sum(1),
...
:
}
但在官方程序例中,却写成
db.collection('items').aggregate()
.bucket({
groupBy: '$price',
boundaries: [0, 50, 100],
default: 'other',
output: {
count: $.sum(), // ---------- 错误, 应改为 $.sum(1)
ids: $.push('$_id')
}
})
.end()
返回结果如下:
[
{
"_id": 0,
"count": 2,
"ids": [
"1",
"3"
]
},
{
"_id": 50,
"count": 2,
"ids": [
"2",
"4"
]
},
{
"_id": "other",
"count": 22, // ---------- 错误, 应改为 1
"ids": [
"5"
]
}
]
2、Aggregate.bucket(object: Object): Aggregate
output: {
count: $.sum(1),
...
:
}
但在官方程序例中,却写成
db.collection('items').aggregate()
.bucket({
groupBy: '$price',
boundaries: [0, 50, 100],
default: 'other',
output: {
count: $.sum(), // ---------- 错误, 应改为 $.sum(1)
ids: $.push('$_id')
}
})
.end()
返回结果如下:
[
{
"_id": 0,
"count": 2,
"ids": [
"1",
"3"
]
},
{
"_id": 50,
"count": 2,
"ids": [
"2",
"4"
]
},
{
"_id": "other",
"count": 22, // ---------- 错误, 应改为 1
"ids": [
"5"
]
}
]
3、 Aggregate.bucketAuto(object: Object): Aggregate
db.collection('items').aggregate()
.bucket({ // ---------- 错误, 应改为 bucketAuto
groupBy: '$price',
buckets: 3,
})
.end()
4、 Aggregate.limit(value: number): Aggregate
db.collection('items').aggregate()
.match({
price: $.gt(20) // ---------- 错误, 应改为 _.gt(20)
})
.sort({
price: 1,
})
.limit(2)
.end()
返回结果如下:【不知道哪里来的结果,根本不正确,正确的结果是:_id(2)与_id(4)】
{
"_id": "3",
"price": 20
}
{
"_id": "4",
"price": 80
}
应该其他还有,拜托修正!