欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-07-15 23:02:01
...

解决"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

}