是否有可能有一个reduce函数返回一个平面对象而不是类似地图的东西?
更多细节:
db.getCollection('calls').mapReduce(function () {
emit(this.reportDate + '-' + this.reportTime, {
from: this.caller,
to: this.called,
callEnds: this.callEnds,
callBegins: this.callBegins,
location: this.location
});
}, function (k, v) {
var result = {};
v.forEach(function (value) {
result.from = value.from;
result.to = value.to;
result.callBegins = value.callBegins;
result.callEnds = value.callEnds;
if (value.location) {
result.location = value.location;
}
});
return result;
}, {
out: 'mapReducedCalls'
})
使用这个,输出集合的文档都是
{ "_id" : "k",
"value" :
{ "from" : "b5c06aafa4be00db3d6acadb67b6ceef",
"to" : "0afba72b041e3ccb5a62f0b0b44cceea",
"callEnds" : "01/03/2013 10:45:44",
"callBegins" : "01/03/2013 10:45:40",
"location" : 44763
}
}
虽然我宁愿把它做成一个扁平的物体形式,比如
{ "_id" : "k",
"from" : "b5c06aafa4be00db3d6acadb67b6ceef",
"to" : "0afba72b041e3ccb5a62f0b0b44cceea",
"callEnds" : "01/03/2013 10:45:44",
"callBegins" : "01/03/2013 10:45:40",
"location" : 44763
}