Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 8, 2018 00:07
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 parzibyte/9c796b26a528a4255d9e53019049c4b3 to your computer and use it in GitHub Desktop.
Save parzibyte/9c796b26a528a4255d9e53019049c4b3 to your computer and use it in GitHub Desktop.
db.libros.aggregate([
{ "$group": {
"_id": { "isbn": "$isbn" },
"dups": { "$push": "$_id" },
"count": { "$sum": 1 }
}},
{ "$match": { "count": { "$gt": 1 } }}
]).forEach(function(doc) {
doc.dups.shift();
db.libros.remove({ "_id": {"$in": doc.dups }});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment