Last active
May 24, 2017 15:47
-
-
Save belsrc/8623ba3da74f855ac13b32ee2941b1de to your computer and use it in GitHub Desktop.
Mongo Unique Created At Days
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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