Skip to content

Instantly share code, notes, and snippets.

@rhyskeepence
Created September 4, 2012 14:21
Show Gist options
  • Save rhyskeepence/3621591 to your computer and use it in GitHub Desktop.
Save rhyskeepence/3621591 to your computer and use it in GitHub Desktop.
group by day with aggregate function
db.prod.aggregate(
{ $match : { _id: { $gte: someTimestamp }}},
{ $group :
{
_id : { $subtract: ["$_id", { $mod: ["$_id", 86400000] } ] } ,
averagePerDay : { $avg : "$threadCount" }
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment