I want to calculate users accumulated by dates. I have the following map reduction features:
var m = function(){
var d = new Date(parseInt(this._id.toString().slice(0,8), 16)*1000);
var t = d.getTime();
emit(d2,d3);
};
var r = function(k,v){
return v[0];
};
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);
When I start, I get an error message:
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
}
It seems impossible to call db. methods inside finalization. Why?
I knoq, which I can call from map () and from reduce ()
bug0r source
share