Created
February 9, 2014 13:59
-
-
Save gurdotan/8899480 to your computer and use it in GitHub Desktop.
MongoDB corollary of SQL's "SELECT DISTINCT ... GROUP BY"
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
db.events.aggregate( | |
{'$group' : {_id : "$platform", devices: {"$addToSet" : "$device_id"} } }, | |
{"$unwind" : "$devices" }, | |
{"$group" : {_id : "$_id", count: {"$sum" : 1}}} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment