マップのようなものの代わりにフラットオブジェクトを返す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
}