【发布时间】:2011-03-23 18:36:45
【问题描述】:
给定这样的文件:
{ "_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 为空?
【问题讨论】:
-
在 MongoDB 论坛上将此问题与相同的问题相关联:groups.google.com/group/mongodb-user/browse_thread/thread/…