我正在阅读 Mongodb 关于聚合框架和 Mapreduce 的文档,但仍然不知道从哪里开始聚合数组中整数的“列”。Fi 拥有这些文件:
[{ "_id" : "A", "agent" : "006", "score" : [ 1, 0, 0 ], "qv" : [ 1, 0, 1, 0, 1 ] },
{ "_id" : "B", "agent" : "006", "score" : [ 0, 1, 0 ], "qv" : [ 1, 0, 1, 0, 1 ] },
{ "_id" : "C", "agent" : "006", "score" : [ 1, 0, 0 ], "qv" : [ 1, 0, 1, 0, 0 ] },
{ "_id" : "D", "agent" : "007", "score" : [ 1, 0, 0 ], "qv" : [ 1, 0, 1, 0, 0 ] }]
预期的结果应该是这样的:
[
{"agent": "006", "score": [2, 1, 0], "qv": [3, 0, 3, 0, 2]},
{"agent": "007", "score": [1, 0, 0], "qv": [1, 0, 1, 0, 0]}
]
聚合框架是否足以完成这项任务,还是我应该瞄准 Mapreduce?