count on distinct value mongodb aggregation code example Example: mongodb count distinct db.collection.distinct('field').length