Skip to content

Instantly share code, notes, and snippets.

@japharr
Created March 9, 2022 23:58
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 japharr/3e7c1a3e6d0cd38706f1836b262a8cff to your computer and use it in GitHub Desktop.
Save japharr/3e7c1a3e6d0cd38706f1836b262a8cff to your computer and use it in GitHub Desktop.
Removed duplicates items from Db
// Using loop to delete duplicate items but one
db.amazon_sales.find({}, {asin:1}).sort({_id:1}).forEach(function(doc){
db.amazon_sales.remove({_id:{$gt:doc._id}, asin:doc.asin});
})
// indexing the field
db.amazon_sales.createIndex( { "asin": 1 }, { unique: true } )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment