Handling multiple errors in InsertMany function with Ordered: false

Hey everyone :slight_smile:
I’m using Golang’s MongoDB driver and I’m facing an issue I would love getting assistance with.
I try running InsertMany() with Ordered: false in order to ignore duplicate key errors (I use a unique index for a specific field which should be unique) and keep on inserting all the other documents.

It works perfectly fine (in the happy flow :slight_smile:), however I’m not sure it’s possible to handle errors if multiple different errors arise in the same insertion - the mongo.IsDuplicateKeyError() function seems to return true even if the insertion returns 10 errors and only 1 of them is duplicate key :frowning:

Is there any solution I can use to ignore duplicate key errors but still be able to handle other errors, should they occur?

Thank you!

Hi @Adir_Halfon and welcome to MongoDB community forums!!

Based on the above statement, can you please clarify is you are looking for a solution where the mongo.IsDuplicateKeyError() is not working as expected?

It would be very helpful for me to provide you with assistance if you could help me understand the concern in more detail.

Warm Regards