Created
March 9, 2022 23:58
-
-
Save japharr/3e7c1a3e6d0cd38706f1836b262a8cff to your computer and use it in GitHub Desktop.
Removed duplicates items from Db
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
// 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