Skip to content

Instantly share code, notes, and snippets.

@belsrc
Last active May 24, 2017 15:47
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 belsrc/8623ba3da74f855ac13b32ee2941b1de to your computer and use it in GitHub Desktop.
Save belsrc/8623ba3da74f855ac13b32ee2941b1de to your computer and use it in GitHub Desktop.
Mongo Unique Created At Days
db.getCollection('collection').aggregate([
{ $match: { $and: [
{ created_at: { $exists: true } },
{ created_at: { $ne: null } }
] } },
{ $project: {
month: { $month: "$created_at" },
year: { $year: "$created_at" },
day: { $dayOfMonth: "$created_at" } } },
{ $group: { _id: { "year": "$year", "month": "$month", "day": "$day" } } },
{ $sort: { _id: -1 } }
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment