Get distinct value in MongDB

 db.the_collection_name.distinct('the_field_name')

 

To get count of distinct value

var collection = "the_collection_name"; var field = "the_field_name";
db[collection].distinct(field).forEach(
    function(value) {
        print(field + ", " + value + ": " + db[collection].count({[field]: value}))
    }
)

Comments

Popular posts from this blog

Useful aliases

Enable Search Engine Friendly (Pretty URLs) in Yii2