How to Ignore Duplicate Key Errors Safely Using insert_many
You can deal with this by inspecting the errors produced with BulkWriteError. This is actually an “object” which has several properties. The interesting parts are in details: import pymongo from bson.json_util import dumps from pymongo import MongoClient client = MongoClient() db = client.test collection = db.duptest docs = [{ ‘_id’: 1 }, { ‘_id’: 1 … Read more