I\'m working on a query to find cities with most zips for each state:
db.zips.distinct(\"state\", db.zips.aggregate([ {$group:{_id:{state:\"$state\", city:\"
You can use $addToSet with the aggregation framework to count distinct objects.
For example:
db.collectionName.aggregate([{ $group: {_id: null, uniqueValues: {$addToSet: "$fieldName"}} }])