// JQL Aggregate
db.collection('goods').aggregate().sort({
price: -1
}).group({
_id: "$category",
maxGoodsName: {$first: "$name"},
maxGoodsPrice: {$first: "$price"},
minGoodsName: {$last: "$name"},
minGoodsPrice: {$last: "$price"}
}).project({
_id: 0,
category: "$_id",
maxGoods: {
name: "$maxGoodsName",
price: "$maxGoodsPrice"
},
minGoods: {
name: "$minGoodsName",
price: "$minGoodsPrice"
}
}).end()
上面列子如何使用JQL groupBy的方式
w***@163.com (作者)
文档上写着max、min是针对sort之后的最大最小
2023-03-14 19:39
DCloud_uniCloud_WYQ
回复 w***@163.com: 哪个文档写的?https://uniapp.dcloud.net.cn/uniCloud/cf-database-aggregate-operator.html#max 看这个
2023-03-14 20:03