mongorestore command replace existing records?

前端 未结 4 1958
孤城傲影
孤城傲影 2021-01-01 10:29

Is there a way for mongorestore to replace the records existing in the database instead of skipping it which is the default behavior ?

I\'m currently using the lates

4条回答
  •  旧时难觅i
    2021-01-01 10:42

    I have solved this using

    1. restore the collection and write the output to file (errors)
    mongorestore --db database -c collection ~/path_to_bson > output.txt 2>&1
    
    1. filter out the lines containing - E11000 duplicate key error collection ...ObjectId(...)
    2. then using multi-edit tool (in my case sublime) convert those lines to db.collection.remove({_id: ObjectId(...)})
    3. restore the database again.

提交回复
热议问题