Skip to content

Instantly share code, notes, and snippets.

@josemiguelq
Last active May 9, 2018 21:04
Show Gist options
  • Save josemiguelq/18a0af3cff3bdc7aaffa7b4102ae2114 to your computer and use it in GitHub Desktop.
Save josemiguelq/18a0af3cff3bdc7aaffa7b4102ae2114 to your computer and use it in GitHub Desktop.
mongo query group by day and count
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