Skip to content

Instantly share code, notes, and snippets.

@mirven
Created October 20, 2009 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mirven/214619 to your computer and use it in GitHub Desktop.
Save mirven/214619 to your computer and use it in GitHub Desktop.
db.events.group(
{
cond : { event : "foo" },
keyf : function(obj) {
return { month : obj.timestamp.getMonth()+1, day : obj.timestamp.getDate(), year : obj.timestamp.getYear()+1900 }
},
reduce : function(obj,prev) { prev.count++; prev.users[obj.user_id] = 1; },
initial : { count : 0, users : {} },
finalize : function(prev) {
var count = 0;
for (var user_id in prev.users) {
count++;
}
prev.users = count;
}
}
)
// results
[{"month" : 10 , "day" : 20 , "year" : 2009 , "count" : 2 , "users" : 100},{"month" : 10 , "day" : 19 , "year" : 2009 , "count" : 2 , "users" : 100}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment