duplicate documents mongodb code example
Example: duplicated documens mongodb
db.users.aggregate([
{$group: {
_id: {email: "$email"},
uniqueIds: {$addToSet: "$_id"},
count: {$sum: 1}
}
},
{$match: {
count: {"$gt": 1}
}
},
{$sort: {
count: -1
}
}
]);