分享

mongodb mapreduce怪异的结果

yao12712q 发表于 2013-10-17 21:37:56 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 2 4252
// ※※※※※※※※※※※※※※※※※※※   数据加载   ※※※※※※※※※※※※※※※※※※※
db.proc.remove();
for(var i = 10; i { "_id" : 6, "value" : { "class" : 6, "count" : 60, "sum" : NaN, "max" : NaN } }
{ "_id" : 7, "value" : { "class" : 7, "count" : 70, "sum" : 3115, "max" : 79 } }
{ "_id" : 8, "value" : { "class" : 8, "count" : 80, "sum" : NaN, "max" : NaN } }
{ "_id" : 9, "value" : { "class" : 9, "count" : 90, "sum" : NaN, "max" : NaN } }
{ "_id" : 10, "value" : { "class" : 10, "count" : 100, "sum" : NaN, "max" : NaN } }
{ "_id" : 11, "value" : { "class" : 11, "count" : 110, "sum" : NaN, "max" : NaN } }
db.proc_res3.find()
{ "_id" : 4, "value" : { "class" : 4, "count" : 40, "sum" : 1180, "max" : 49 } }
{ "_id" : 5, "value" : { "class" : 5, "count" : 50, "sum" : 1725, "max" : 59 } }
{ "_id" : 6, "value" : { "class" : 6, "count" : 60, "sum" : NaN, "max" : NaN } }
{ "_id" : 7, "value" : { "class" : 7, "count" : 70, "sum" : NaN, "max" : NaN } }
{ "_id" : 8, "value" : { "class" : 8, "count" : 80, "sum" : 3960, "max" : 89 } }
{ "_id" : 9, "value" : { "class" : 9, "count" : 90, "sum" : 4905, "max" : 99 } }
{ "_id" : 10, "value" : { "class" : 10, "count" : 100, "sum" : NaN, "max" : NaN } }
{ "_id" : 11, "value" : { "class" : 11, "count" : 110, "sum" : NaN, "max" : NaN } }
db.proc_res5.find()
{ "_id" : 6, "value" : { "class" : 6, "count" : 60, "sum" : 2370, "max" : 69 } }
{ "_id" : 7, "value" : { "class" : 7, "count" : 70, "sum" : NaN, "max" : NaN } }
{ "_id" : 8, "value" : { "class" : 8, "count" : 80, "sum" : NaN, "max" : NaN } }
{ "_id" : 9, "value" : { "class" : 9, "count" : 90, "sum" : 4905, "max" : 99 } }
{ "_id" : 10, "value" : { "class" : 10, "count" : 100, "sum" : 5950, "max" : 109 } }
{ "_id" : 11, "value" : { "class" : 11, "count" : 110, "sum" : NaN, "max" : NaN } }
db.proc_res6.find()
{ "_id" : 7, "value" : { "class" : 7, "count" : 70, "sum" : 3115, "max" : 79 } }
{ "_id" : 8, "value" : { "class" : 8, "count" : 80, "sum" : NaN, "max" : NaN } }
{ "_id" : 9, "value" : { "class" : 9, "count" : 90, "sum" : NaN, "max" : NaN } }
{ "_id" : 10, "value" : { "class" : 10, "count" : 100, "sum" : NaN, "max" : NaN } }
{ "_id" : 11, "value" : { "class" : 11, "count" : 110, "sum" : NaN, "max" : NaN } }
db.proc_res9.find()
{ "_id" : 10, "value" : { "class" : 10, "count" : 100, "sum" : 5950, "max" : 109 } }
{ "_id" : 11, "value" : { "class" : 11, "count" : 110, "sum" : NaN, "max" : NaN } }
db.proc_res10.find()
{ "_id" : 11, "value" : { "class" : 11, "count" : 110, "sum" : NaN, "max" : NaN } }
认能告诉我这是为什么吗?
              
               
               

已有(2)人评论

跳转到指定楼层
boYwell 发表于 2013-10-17 21:38:55

            哪个版本?
        
回复

使用道具 举报

liyjs 发表于 2013-10-17 21:39:31

            m = function(){emit(this.class, {max:this.id, sum:this.id, count:1})}
r = function(key, values){
var ct = 0, sm = 0, mx = 0;  
for(var i = 0; i < values.length; i++){
ct += values[i].count;  
sm += values[i].sum;  
mx = Math.max(mx, values[i].max);
}  
return {max: mx,  sum:sm, count:ct};
}
        
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条