mongdb语法练习------wuwangqiang----2--分组练习

#查询每个栏目下的商品数量 { key:{cat_id:1}, cond:{}, reduce:function(curr,result) { result.cnt += 1; }, initial:{cnt:0} } #查询每个栏目下价格高于50元的商品数量 { key:{cat_id:1}, cond:{shop_price:{KaTeX parse error: Expected 'EOF', got '}' at position 6: gt:50}̲}, reduce:funct…group:{_id:“KaTeX parse error: Expected '}', got 'EOF' at end of input: cat_id",total:{sum:1}}} ] #查询goods下有多少条商品,select count(*) from goods [ {KaTeX parse error: Expected '}', got 'EOF' at end of input: …id:null,total:{sum:1}}} ] #查询每个栏目下 价格大于50元的商品个数 [ {KaTeX parse error: Expected '}', got 'EOF' at end of input: …h:{shop_price:{gt:50}}}, {KaTeX parse error: Expected '}', got 'EOF' at end of input: group:{_id:"cat_id”,total:{KaTeX parse error: Expected 'EOF', got '}' at position 6: sum:1}̲}} ] #查询每个栏目下 价…match:{shop_price:{KaTeX parse error: Expected 'EOF', got '}' at position 6: gt:50}̲}}, {group:{_id:“KaTeX parse error: Expected '}', got 'EOF' at end of input: cat_id",total:{sum:1}}}, {KaTeX parse error: Expected '}', got 'EOF' at end of input: match:{total:{gte:3}}} ] #查询每个栏目下的库存量 [ {KaTeX parse error: Expected '}', got 'EOF' at end of input: group:{_id:"cat_id” , total:{ s u m : " sum:" sum:"goods_number"}}}, ] #查询每个栏目下的库存量,并按库存量排序 [ {KaTeX parse error: Expected '}', got 'EOF' at end of input: group:{_id:"cat_id" , total:{ s u m : " sum:" sum:"goods_number"}}}, {KaTeX parse error: Expected 'EOF', got '}' at position 15: sort:{total:1}}̲ ] #查询每个栏目下的库存量…group:{_id:"KaTeX parse error: Expected '}', got 'EOF' at end of input: …t_id" , total:{sum:"KaTeX parse error: Expected 'EOF', got '}' at position 14: goods_number"}̲}}, {sort:{total:1}}, {KaTeX parse error: Expected 'EOF', got '}' at position 8: limit:3}̲ ] #查询每个栏目的商品平均…group:{_id:"KaTeX parse error: Expected '}', got 'EOF' at end of input: cat_id" , avg:{avg:"KaTeX parse error: Expected 'EOF', got '}' at position 12: shop_price"}̲}}, {sort:{avg:-1}} ] mapReduce 随着"大数据"概念而流行. 其实mapReduce的概念非常简单, 从功能上说,相当于RDBMS的 group 操作 mapReduce的真正强项在哪? 答:在于分布式,当数据非常大时,像google,有N多数据中心, 数据都不在地球的一端,用group力所不及. group既然不支持分布式,单台服务器的运算能力必然是有限的. 而mapRecuce支持分布式,支持大量的服务器同时工作, 用蛮力来统计. mapRecuce的工作过程: map–>映射 reduce->归约 map: 先是把属于同一个组的数据,映射到一个数组上.cat_id-3 [23,2,6,7] reduce: 把数组(同一组)的数据,进行运算. 用mapReduce计算每个栏目的库存总量 map函数 var map = function() { emit(this.cat_id,this.goods_number); } var reduce = function(cat_id,numbers) { return Array.sum(numbers); } db.goods.mapReduce(map,reduce,{out:‘res’}); #用mapReduce计算每个栏目下商品的平均价格 var map = function() { emit(this.cat_id,this.shop_price); } var reduce = function(cat_id,values) { return Array.avg(values); } db.goods.mapReduce(map,reduce,{out:‘res’});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值