Created
December 5, 2012 08:43
-
-
Save sunny0425/4213910 to your computer and use it in GitHub Desktop.
mongo aggregate script
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
# 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