avatasia
2012-03-01 11:20:00 +08:00
e = function(){
return db.STATISDAY.count();
}
l = function(){
db.log.save({t: new Date()});
}
m = function(){
log();
emit({PEPDATE:this.PEPDATE, xx:xx()}, {count: 1});
}
r = function(k, vs){
log();
var r = {count: 0};
vs.forEach(function(v){
r.count += v.count;
})
return {aa: xx(), count: r.count};
}
db.STATISDAY.mapReduce(m, r, {query:{PEPDATE: 20120130}, out:{inline:1}, scope:{xx:e, log: l}});
在map里可以运行外部函数,但是只能读取db,不能写入db。貌似用了db.eval("map()").
2. 以前格式化result的double类型,都是写个finalize,然后调用runcommand,现在可以在reduce里return,省略了finalize一步,这样就可以直接调用db.xx.mapReduce,不用写那么多代码了。