Skip to content

Instantly share code, notes, and snippets.

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