我在mongodb中有这个文件:
{
"_id":"26/04/2015 09:50",
"reservations":130,
"Event_types":[
{
"type":"Party",
"events":[
{
"eventName":"After Party",
"total_count":130,
"by":[
{
"siteName":"club8",
"countArray":[
{
"bucket":"default",
"value":40
}
]
},
{
"siteName":"PostParty",
"countArray":[
{
"bucket":"1",
"value":70
},
{
"bucket":"2",
"value":20
}
]
}
]
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
我正在寻找什么
我希望通过以下字段对"值"字段和组进行求和:
所以对于我希望得到的文件:
我试过的
我已经尝试使用聚合运算符和_id的复合键:
db.testing.aggregate(
{
$group : {
_id :
{
type:'$Event_types.type',
name: '$Event_types.events.eventName',
siteName: '$Event_types.events.by.siteName'
}
, total : { $sum : '$Event_types.events.by.countArray.value' }
}
});
Run Code Online (Sandbox Code Playgroud)
结果
一个文档,有3个数组 …
mongodb ×1