MongoDB : Calculating wrongly in mapReduce -


this collection named logins

db.logins.find().pretty()         "cust_id" : "testuser",        "created_at" : "2011-03-11 10:31:02.765"        "cust_id" : "testuser",       "created_at" : "2011-03-11 10:31:02.765" 

i trying find out logins of each user based on date

i tried way

var m = function() {     var aux = this.created_at.indexof(' ');     emit({cust:this.cust_id,daterr:this.created_at.substring(0,aux)},1); }  var r = function(k, values) {   var l = values.length;   var r = 0;   var i;   (i=0; i<l; i++) {     r+=l;   }   return r; }   q = function() {         var query = {"created_at": {$lt: "2013-04-30 11:19:52.587"}}         return query;     }  db.logins.mapreduce(m, r, { query : q(), out :  "userlogincountmonthly" }); 

i getting following output

db.userlogincountmonthly.find().pretty()  { "_id" : { "cust" : "testuser", "daterr" : "2011-03-11" }, "value" : 4 } 

what see value must 2 , shown 4

could please tell me why displaying wrong ??

i may totally off in since i've never used mongodb's mapreduce , i'm not quite sure you're trying achieve in reduce, looks wrong;

var l = values.length; var r = 0; var i; (i=0; i<l; i++) {   r+=l; } return r; 

if values.length 2, loop twice, each time adding 2, returning 4.

as far can see since want count, simple return values.length make more sense reduce function.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -