mongodb count number of distinct values per field/key code example Example: mongodb count distinct db.collection.distinct('field').length