Skip to content

Instantly share code, notes, and snippets.

@chrisckchang
Created April 30, 2014 23:51
Show Gist options
  • Save chrisckchang/12ffac9817ecd615ec23 to your computer and use it in GitHub Desktop.
Save chrisckchang/12ffac9817ecd615ec23 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