Last active
December 19, 2016 16:59
-
-
Save anapaulagomes/138958fceb012c9616cb to your computer and use it in GitHub Desktop.
Group array attributes, sum then and order from the biggest to the smallest - MongoDB
This file contains hidden or 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
var pipeline = [{$unwind: '$comments'}, {$group: {_id: '$comments.author', numberOf: {$sum: 1}}}, {$sort: {numberOf:-1}}] | |
db.posts.aggregate(pipeline) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment