鑑於這樣的文件:的MongoDB的Map/Reduce鬥爭
{ "_id": {
"$oid": "4d88ca367d190a0aa4e27806" }, "Rows": [
{
"Columns": {
"Date": "Tue, 02 Aug 2011 00:00:00 GMT -04:00",
"Col2": 33
"Col3": 44
}
},
{
"Columns": {
"Date": "Mon, 17 Oct 2011 00:00:00 GMT -04:00",
"Col2": 55
"Col3": 66
}
} ], "DocName": "For My Eyes Only", "DocIdentifier": 3322445 }
及以下的Map/Reduce函數:
function() {
this.Rows.forEach(function(bulkcol) {
emit(this.DocName, { TrendValue: bulkcol.Columns.Col2 });
});
};
function(key, values) {
var sum = 0;
values.forEach(function(currTrend) {
sum += currTrend.TrendValue;
});
return {DocName: key, TrendValue: sum};
};
我得到以下輸出:
{
"_id": null,
"value": {
"DocName": null,
"TrendValue": 88
}
}
爲什麼是DocName null?
鏈接就此問題向同樣在MongoDB論壇上:http://groups.google.com/group/mongodb-user/browse_thread/thread/44219c4994e51476 – AdaTheDev 2011-03-24 13:31:57