Skip to content

Instantly share code, notes, and snippets.

@mdippery
Last active August 29, 2015 14:01
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 mdippery/8ff4973b4a151304d517 to your computer and use it in GitHub Desktop.
Save mdippery/8ff4973b4a151304d517 to your computer and use it in GitHub Desktop.
Group a set of MongoDB documents by day, finding the maximum value for each day
db.samples.aggregate([ {$match: {user: 28804}}, {$group: {_id: {year: {$year: "$timestamp"}, month: {$month: "$timestamp"}, day: {$dayOfMonth: "$timestamp"}}, reputation: {$max: "$reputation"}}}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment