Created
June 15, 2012 09:33
mongodb count embeded objects by an atrribute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var map = function() { emit(this.e, { notifications : this.notifications});}; | |
var reduce = function(key, values) { | |
var count = 0; | |
values.forEach(function(docs) { | |
for(var doc in docs.notifications){ | |
if(docs.notifications[doc].date>1332836355){ | |
count+=1; | |
} | |
} | |
}); | |
return { c : count}; | |
}; | |
db.collection1.mapReduce(map, reduce, {out: collection2}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment