我想通过按日期累积来计算用户。我有以下地图减少功能:
var m = function(){
// creation date
var d = new Date(parseInt(this._id.toString().slice(0,8), 16)*1000);
// ticks
var t = d.getTime();
emit(d2,d3);
};
var r = function(k,v){
return v[0]; // just go next with ticks
};
var opts = { out : { merge : "UserAccum", db : "Metric"},
finalize: function(k,v){
var str = "parseInt(this._id.toString().slice(0,8), 16)*1000 <= "+v;
return db.User.count({$where:str});
}
};
var res = db.Provider.mapReduce(m, r, opts);
运行时,出现错误:
Sat May 12 17:47:23 uncaught exception: map reduce failed:{
"assertion" : "invoke failed: JS Error: TypeError: db has no properties
nofile_b:2",
"assertionCode" : 9004,
"errmsg" : "db assertion failure",
"ok" : 0
}
似乎无法调用 db. finalize 里面的方法。为什么?
我知道我可以从 map() 和 reduce() 调用