Skip to content

Instantly share code, notes, and snippets.

@sunny0425
Created December 5, 2012 08:43
Show Gist options
  • Save sunny0425/4213910 to your computer and use it in GitHub Desktop.
Save sunny0425/4213910 to your computer and use it in GitHub Desktop.
mongo aggregate script
# Here comments are embedded_in letters
$ mongo
> db.letters.aggregate(
{ $unwind : "$comments"},
{ $match: { "comments.created_at": { $gt: new Date('01/01/2012') } } },
{ $group: {
_id : "$_id",
comment_count: { $sum : 1 }
} },
{ $sort : { comment_count : -1 }},
{ $limit : 5}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment