how to do count distinct in mongodb in aggregation step code example Example: mongodb count distinct db.collection.distinct('field').length