mongo 3 duplicates on unique index - dropDups

前端 未结 3 1013
刺人心
刺人心 2020-12-13 10:32

In the documentation for mongoDB it says: \"Changed in version 3.0: The dropDups option is no longer available.\"

Is there anything I can do (other than downgrading)

3条回答
  •  独厮守ぢ
    2020-12-13 10:57

    pip install mongo_remove_duplicate_indexes

    best way will be to create a python script or in any language you prefer,iterate the collection ,create new collection with a unique index set to true with db.collectionname.createIndex({'indexname':1},unique:true),and insert your documents from previous collection to new collection and since key you wanted to be distinct or duplicates removed will not be inserted in ur new collection and u can handle the ecxeption easily with exception handling

    check out the package source code for the example

提交回复
热议问题