當我這樣做對我的收藏此查詢...節點與貓鼬和總金額嵌套領域
models.Project.find(function(err, result) {
//result = doc below
}).populate('media')
...我得到這樣的結果:
{
_id: 57f36baa6cf34d079c8474a0,
code: 'ZMIA',
__v: 0,
media:[
{
_id: 57f36bb26cf34d079c847766,
project_code: 'ZMIA',
amount: 228,
__v: 0
},
{
_id: 57f36bb26cf34d079c84775c,
project_code: 'ZMIA',
amount: 250,
__v: 0
}
]
},
{
_id: 57f36baa6cf34d079c8474a1,
code: 'ZMJU',
__v: 0,
media: []
}
media
是一個REF域。如何將嵌套媒體對象(如果存在)聚合到$sum
amount
字段並將結果分組爲project_code
?
目前還不清楚預期的結果是什麼。你能否詳細說明一下? – styvane