Thursday, 29 August 2013

MongoDB: Sort distinct keys by number of occurances

MongoDB: Sort distinct keys by number of occurances

I have a bunch of repository data that I've scrapped from Github. Each
repository has a language key and with pymongo I am able to the list of
all languages in my database with db.distinct('language'). I would like to
sort the list by the number of occurrences so that the first language is
my list is the language associated with the most repositories. Is it
possible to do this in one query instead of querying the database for the
count of each language?

No comments:

Post a Comment