'WriteConflict error: this operation conflicted with another operation. Please retry your operation or multi-document transaction.'

I am getting from Mongodb Exception:

Caused by: com.mongodb.MongoCommandException: Command failed with error 112 (WriteConflict): 'WriteConflict error: this operation conflicted with another operation.

Got this error when used @Transactional Spring Boot Annotation. Tried to insert two documents, one should be inserted successfully and other should roll back because of duplicate key (Unique Index).
But this exception was not expected, instead DuplicateKeyException was expected. Before using @Transactional, I was getting DuplicateKeyException.

Hello @Neha_Maheshwari2 ,

Welcome to The MongoDB Community Forums! :wave:

Can you share the MongoDB version being used?

Regards,
Tarun

Hi @Tarun_Gaur,

Thank you !!
Version of MongoDB we are currently using is 4.6.1.

Regards,
Neha Maheshwari