{"name":"A","pro":[{"name":"A1","total":1},{"name":"A2","total":2},{"name":"A3","total":3}......]}
{"name":"C","pro":[{"name":"C1","total":1},{"name":"C2","total":2},......]}
{"name":"B","pro":[{"name":"B1","total":1},{"name":"B2","total":2},{"name":"B3","total":3}......]}
上面的数据库中,怎么直接求所有total的和?不用分组。
db.collection('CARS').aggregate().group({
_id: null,
total: $.sum('$pro.total')
}).end()
这样测试不成功!
unwind一下先,再group