Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mongoDB mapReduce:reduce函数返回普通对象而不是贴图_Mongodb_Mapreduce - Fatal编程技术网

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

mongoDB mapReduce:reduce函数返回普通对象而不是贴图,mongodb,mapreduce,Mongodb,Mapreduce,有没有可能使用reduce函数来返回平面对象而不是类似于贴图的对象 更多详情: db.getCollection('calls').mapReduce(function () { emit(this.reportDate + '-' + this.reportTime, { from: this.caller, to: this.called, callEnds: this.callEnds, callBegins: thi

有没有可能使用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
}

不,当前需要“value”字段(假设这就是您所说的类似于地图的东西)