WriteConflicts occur in mongodb when two or more write operations try to modify a document at the same time. Since mongodb uses optimistic concurrency control, it fails the latter operation and retries the latter write operation internally.
Transactions in mongodb can be implemented in 2 ways:
- Core api - the retry logic is not implemented internally but rather left for the developers to incorporate
- Callback api - the retry logic is already incorporated
I believe you are using the core api approach and that's why it is giving this error. Try switching to callback api approach to solve it.