Skip to content

Instantly share code, notes, and snippets.

@bleft
Created April 28, 2017 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bleft/cac9317fe3327f0d856513c00aeb857f to your computer and use it in GitHub Desktop.
Save bleft/cac9317fe3327f0d856513c00aeb857f to your computer and use it in GitHub Desktop.
mongo-helper
// find duplicates
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