日期:2014-05-16  浏览次数:20440 次

mongdb "errmsg" : "exception: 'out' has to be a string or an object"

解决"errmsg" : "exception: 'out' has to be a string or an object"

map=function (){ for(var key in this){ emit(key, {count:1}); }}

reduce=function (key, emits){ total=0; for(var i in emits){ total+=emits[i].count; } return{"count":total}; }

?

> r=db.runCommand({"mapreduce":"users", "map":map,"reduce":reduce})

{

"errmsg" : "exception: 'out' has to be a string or an object",

"code" : 13606,

"ok" : 0

?

}

在mongodb-src-r2.4.5版本中需要指定out才能正常查询数据

> r=db.runCommand({"mapreduce":"users", "map":map,"reduce":reduce,"out":"sss"})

{

"result" : "sss",

"timeMillis" : 6,

"counts" : {

"input" : 3,

"emit" : 12,

"reduce" : 4,

"output" : 4

},

"ok" : 1

}

?