Skip to content

Instantly share code, notes, and snippets.

@cschlyter
Created May 2, 2013 14:45
Show Gist options
  • Save cschlyter/5502697 to your computer and use it in GitHub Desktop.
Save cschlyter/5502697 to your computer and use it in GitHub Desktop.
MongoDB: group data by day (group)
db.link_access.group(
{
keyf: function(doc) {
var date = new Date(doc.date);
var dateKey = (date.getMonth()+1)+"/"+date.getDate()+"/"+date.getFullYear()+'';
return {'day': dateKey};
},
cond: {short_id: "N"},
initial: {count:0},
reduce: function(obj, prev) {prev.count++;}
});
//http://stackoverflow.com/questions/5168904/group-by-dates-in-mongodb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment