Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mongo Query that counts the number of duplicate fields in a collection
db.article.aggregate([
{ $group: {
_id: { name: "$name" },
uniqueIds: { $addToSet: "$_id" },
count: { $sum: 1 }
} },
{ $match: {
count: { $gte: 2 }
} },
{ $sort : { count : -1} },
{ $limit : 10 }
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.