Skip to content

Instantly share code, notes, and snippets.

@cschlyter
Created June 12, 2013 16:46
Show Gist options
  • Save cschlyter/5767048 to your computer and use it in GitHub Desktop.
Save cschlyter/5767048 to your computer and use it in GitHub Desktop.
MongoDB: group by day (aggregate)
var mention_id = 620996;
db.mentionStats.aggregate([
{ $match: {'mention_id': mention_id}},
{ $group: {'_id': {
'year': { '$year': "$verification_date" },
'month': { '$month': "$verification_date" },
'day': { '$dayOfMonth': "$verification_date" }
},
'retweets': { $last: "$retweets" }}},
]).result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment