MongoDB数据分析之MapReduce

1.关于数据类型:如果是使用控制台插入的数据,你插入的数字,很可能存成了Double,而想存成整型,则必须要用NumberInt()、NumberLong()                         来,参考网址:http://www.cnblogs.com/lekko/p/3240028.html2.MapReduce映射化简操作图:    参考网址:http
摘要由CSDN通过智能技术生成

1.关于数据类型:如果是使用控制台插入的数据,你插入的数字,很可能存成了Double,而想存成整型,则必须要用NumberInt()、NumberLong()                         来,参考网址:http://www.cnblogs.com/lekko/p/3240028.html


2.MapReduce映射化简操作图:


    参考网址:http://wrox.cn/article/100035881/


3.MapReduce官网格式

     db.runCommand(  
 { mapreduce : <collection>,  
   map : <mapfunction>,  
   reduce : <reducefunction>,  
   out : <see output options below>  
   [, query : <query filter object>]  
   [, sort : <sorts the input objects using this key. Useful for optimization, like sorting by the emit key for fewer reduces>]  
   [, limit : <number of objects to return from collection, not supported with sharding>]  
   [, keeptemp: <true|false>]  
   [, finalize : <finalizefunction>]  
   [, scope : <object where fields go into javascript global scope >]  
   [, jsMode : true]  
   [, verbose : true]  
 }  
);  

参数说明:

mapreduce:要操作的目标集合

map:映射函数(生成键值对序列,作为Reduce函数的参数) 

reduce:统计函数

query:目标记录过滤

sort:对目标记录排序

limit:限制目标记录数量

out:统计结果存放集合(如果不指定则使用临时集合,在客户端断开后自动删除)

keeptemp:是否保留临时集合

finalize:最终处理函数(对reduce返回结果执行最终整理后存入结果集合)

scope:向map、reduce、finalize导入外部变量

verbose:显示详细的时间统计信息

4.例子:对runoob数据库中class集合进行分组,统计各个班级的学生人数(或年龄大于22的人数)

  应用场景:对students集合中的数据进行统计,根据classid显示每个班级的学生数量。初始数据如下:

Shell代码   收藏代码
  1. > db.students.find()  
  2. "_id" : ObjectId("5031143350f2481577ea81e5"), "classid" : 1"age" : 20"name" : "kobe" }  
  3. "_id" : ObjectId("5031144a50f2481577ea81e6"), "classid" : 1"age" : 23"name" : "nash" }  
  4. "_id" : ObjectId("5031145a50f2481577ea81e7"), "classid" : 2"age" : 18"name" : 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值