Created
April 16, 2015 09:37
-
-
Save gurdotan/47e23a480348a02b754c to your computer and use it in GitHub Desktop.
MongoDB aggregation pipeline: group by date (ISO format)
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.users.aggregate( | |
{ | |
"$match": { | |
created_at: { $gte: ISODate("2014-09-01T00:00:00Z") } | |
} | |
}, | |
{ | |
"$project": { | |
_id: 0, | |
"isoDate": { $substr: [ "$created_at", 0, 10 ] } | |
} | |
}, | |
{ | |
"$group": { "_id": "$isoDate", "count": { "$sum": 1 } } | |
}, | |
{ | |
$sort: { "_id": 1 } | |
} | |
).result.forEach(function(doc) { | |
print(doc._id + "," + doc.count); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment