Check the aggregation framework of mongo. For the answer you can use $group operator to group by userid and sorting them based count. Something like this:
Suppose collection name is test:
db.test.aggregate([{"$group":{"_id":"$userid","occurence":{"$sum":1}}},{$sort:{"occurence":-1}}])