Skip to content

Instantly share code, notes, and snippets.

@gartenfeld
Forked from chrisckchang/aggregate-dupes
Last active August 29, 2015 14:10
Show Gist options
  • Save gartenfeld/00cd836db9173ef1f67f to your computer and use it in GitHub Desktop.
Save gartenfeld/00cd836db9173ef1f67f to your computer and use it in GitHub Desktop.
db.collection.aggregate([
{ $group: {
_id: { firstField: "$firstField", secondField: "$secondField" },
uniqueIds: { $addToSet: "$_id" },
count: { $sum: 1 }
}},
{ $match: {
count: { $gt: 1 }
}},
{ $group: {
_id: null,
total_dups: {$sum: "$count"}
}}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment