mongoDB mapReduce:reduce函数返回普通对象而不是map

时间:2013-03-25 10:28:53

标签: mongodb mapreduce

是否可以使用reduce函数返回平面对象而不是类似map的东西?

更多详情:

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
}

1 个答案:

答案 0 :(得分:0)

不,当前需要'value'字段(假设你的意思是地图般的东西)。