title: How to Ignore Duplicate Key Errors Safely Using insert_many
body: <p>I need to ignore duplicate inserts when using insert_many with pymongo, where the duplicates are based on the index. I've seen this question asked on stackoverflow, but I haven't seen a useful answer.</p>
  
  <p>Here's my code snippet:</p>
  
  <pre><code>try:
      results = mongo_connection[db][collection].insert_many(documents, ordered=False, bypass_document_validation=True)
  except pymongo.errors.BulkWriteError as e:
      logger.error(e)
  </code></pre>
  
  <p>I would like the insert_many to ignore duplicates and not throw an exception (which fills up my error logs). Alternatively, is there a separate exception handler I could use, so that I can just ignore the errors. I miss "w=0"...</p>
  
  <p>Thanks</p>