这个mongo查询有什么问题?

时间:2018-11-28 06:46:42

标签: mongodb mongodb-query

db.items.mapReduce({function(){emit(this.name,this.price);},function(key,value){Array.sum(value)},{out:"map_reduce_example"}});

项目是:

{  
   "_id":"5bfe309ff0e3775c684e85c9",
   "name":"sdgjkld",
   "price":"123"
}

错误说明:

2018-11-28T12:16:19.407+0530 E QUERY [thread1] SyntaxError: invalid property id @(shell):1:98

1 个答案:

答案 0 :(得分:0)

尝试一下

var first = function () {
    emit(this.name, this.price);
}
var second = function (key, value) {
    Array.sum(value)
}

db.items.mapReduce(
    first,
    second,
    { out: "map_reduce_example" }
)

OR

{{1}}