Last active
May 9, 2018 21:04
-
-
Save josemiguelq/18a0af3cff3bdc7aaffa7b4102ae2114 to your computer and use it in GitHub Desktop.
mongo query group by day and count
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.sales.aggregate([ | |
{ | |
$group : { | |
_id : {//Agruppated mandatory field (doesnt mean the ObjectId of document) | |
'year' : { '$year': "$createdAt"}, | |
'month' : { '$month': "$createdAt"}, | |
'day' : { '$dayOfMonth': "$createdAt"} | |
}, | |
count:{ | |
$sum:1 | |
} | |
} | |
} | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment