-
-
Save kylemclaren/a28a69071de9a6fec010 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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