我有一系列格式的文件
{
"name": <name>,
"status": {
"statusId": <can be a number which I want to aggregate like 1/2/3/4>
}
}
我想进行汇总status.statusId
-例如5个文档的status.statusId
= 0、3个文档的status.statusId
= 5等。
我试过了
db.getCollection("users").aggregate([
{
$group: { _id: { "status": { "statusId": "$statusId" }}, count: {$sum:1} }
}
])
但这不起作用。
我要去哪里错了?
您应为_id使用点号
db.getCollection("users").aggregate([
{
$group: { _id: "$status.statusId", count: {$sum:1} }
}
])
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句