Skip to content

Instantly share code, notes, and snippets.

@digital-old-school-journey
Last active November 4, 2018 00:33
Show Gist options
  • Save digital-old-school-journey/c053ff47727f2a4c7a71b9dc2d8af718 to your computer and use it in GitHub Desktop.
Save digital-old-school-journey/c053ff47727f2a4c7a71b9dc2d8af718 to your computer and use it in GitHub Desktop.
MongoDB - Query
db.search_logs.aggregate(
[
{
$group : {
_id : {
keyword: "$keyword"
, created: { $dateToString: { format: "%Y-%m-%d", date: "$created_at" } }
}
, users: {
$push: {
username: '$username',
keyword: '$_id.keyword',
created: '$_id.created',
count: { $sum: 1 }
}
}
}
},
{
$match: { '_id.created': { $eq: '2018-07-13' } }
},
{
$sort: { created_at: -1 }
}
]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment