数据如下:
{
"_id":ObjectId("50c1b9932cec6ac068140c37"),
"totalNum":10,
"userData":[
{"user":"aaa", "num":2},
{"user":"bbb", "num":5},
{"user":"ccc", "num":3}
],
"category":"china"
}
{
"_id":ObjectId("50c1a4782cece24074bc4ac5"),
"totalNum":6,
"userData":[
{"user":"aaa", "num":4},
{"user":"ddd", "num":2}
],
"category":"china"
}
以category字段做group,对totalNum和userData求sum,其中userData为嵌套文档,在以category做mapreduce时,把userData嵌套文档再次做mapreduce,期望结果如下:
{
"_id":ObjectId("50c1a4782cece24074bc4ac3"),
"totalNum":16,
"userData":[
{"user":"aaa", "num":6},
{"user":"bbb", "num":5},
{"user":"ccc", "num":3}
{"user":"ddd", "num":2}
],
"category":"china"
}
不知如何实现,请各位大侠指点啊。。。
|
|