mongodb ReferenceError: map is not defined

错误

ReferenceError: map is not defined

 

操作

> map
2017-02-23T14:52:43.197+0800 ReferenceError: map is not defined
> reduce
2017-02-23T14:52:52.121+0800 ReferenceError: reduce is not defined

> db.user.mapReduce(map,reduce,{"out":"collection"})
2017-02-23T14:54:13.693+0800 ReferenceError: map is not defined

 

解释:

map跟reduce未定义

 

解决

1、先查看集合

> db.user.find()
{ "_id" : ObjectId("58ae37681263f741cb833fc2"), "name" : "keilson", "age" : 30,
"gender" : "M" }
{ "_id" : ObjectId("58ae39a11263f741cb833fc3"), "name" : "Tom", "age" : 20, "gen
der" : "M" }
{ "_id" : ObjectId("58ae81c38f72bc301b434c6a"), "name" : "lili", "age" : 25, "ge
nder" : "F" }
{ "_id" : ObjectId("58ae82118f72bc301b434c6b"), "name" : "lili", "age" : 25, "ge
nder" : "F" }

 

2、定义map跟reduce 

 var map= function(){emit(this.name,this.age);}

 var reduce = function(key,values){return Array.sum(values)}



 db.user.mapReduce(map,reduce,{"out":"collection"})


       "result" : "collection",
       "timeMillis" : 53,
       "counts" : {
               "input" : 4,
               "emit" : 4,
               "reduce" : 1,
               "output" : 3
       },
       "ok" : 1

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值