是否有可能有一个减少函数,返回一个平面对象,而不是像地图一样的东西?
更多细节:
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
}
不,'value'字段目前是必需的(假设这就是您所说的类似map的东西)