Count number of occurrences in MongoDB

 db.collection_name.aggregate(
   {$group : { _id : '$field_name', count : {$sum : 1}}},
   {$sort: { count: -1 } }
)

Comments

Popular posts from this blog

Useful aliases

Enable Search Engine Friendly (Pretty URLs) in Yii2