更新时间:2023-02-04 09:13:58
在 $ sort
中使用 $ limit
以获取最大总数:
Use $sort
with $limit
to get the maximum total:
db.items.aggregate([
{ $match: {} },
{ $group: {
_id: '$category',
sumQ: {$sum: '$quantity'}
}
},
{ $sort: {sumQ: -1 } },
{ $limit: 1 }
])