Skip to content

Instantly share code, notes, and snippets.

@zubairalam
Forked from chrisckchang/dupe-finder.js
Last active August 29, 2015 14:16
Show Gist options
  • Save zubairalam/9e0ae05f4ab863e80833 to your computer and use it in GitHub Desktop.
Save zubairalam/9e0ae05f4ab863e80833 to your computer and use it in GitHub Desktop.
// Desired unique index:
// db.collection.ensureIndex({ firstField: 1, secondField: 1 }, { unique: true})
db.collection.aggregate([
{ $group: {
_id: { firstField: "$firstField", secondField: "$secondField" },
uniqueIds: { $addToSet: "$_id" },
count: { $sum: 1 }
}},
{ $match: {
count: { $gt: 1 }
}}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment