Find all the non distinct values of a field in mongodb Find all the non distinct values of a field in mongodb mongodb mongodb

Find all the non distinct values of a field in mongodb


You can do this using .aggregate()

db.collection.aggregate([    { "$group": {        "_id": "$field",        "count": { "$sum": 1 }    }},    { "$match": {        "count": { "$gt": 1 }    }}])

Also see the SQL to Aggregate Mapping examples.