-
-
Save jeffyuhaoliu/6547659 to your computer and use it in GitHub Desktop.
Node.js MongoDB HW#5.1 - Use aggregation framework to calculate the author with the greatest number of comments.
Note: To run this in Terminal, type in... mongo < [file name of this .js file]. This should run the command of the .js file you created with the mongo shell and return back results in Terminal.
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
use blog | |
db.posts.aggregate([{ | |
$unwind: "$comments" | |
}, { | |
$group: { | |
_id: "$comments.author", | |
postcount: { | |
$sum: 1 | |
} | |
} | |
}, { | |
$sort: { | |
postcount: 1 | |
} | |
}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment