How WriteConflict errors are managed in Transactions( MongoDB 4.2)

when the transaction is aborted with writeconflict error, Does transactions are automatically retried and eventually performing the transaction again?.If its so, how long Mongo retries the transaction and does mongo send a successful acknowledgment to the user and what is the probabilty of message loss here in case of failure even after retries.
If Mongo is not automatically performing any retries for write conflict errors occurs in transaction,how can we manage the write conflict error?.

Hi @Kashifa_khan and welcome in the MongoDB Community :muscle: !

Yes, transactions are automatically retried ONCE if they fail because of a transient network error.

Same for all the write operations actually if you didn’t disable the retryWrites and same for the read operations.

The result of write conflicts in transaction depends on the lock. See the docs here:

In any case, for any MongoDB query, you are always supposed to handle the potential errors or exceptions that these functions can raise. If your cluster go down, you will timeout on all the queries and hopefully this shouldn’t take down the back end with it entirely. And even if a query is retried (read or writes) once, it has to answer before the timeout time you have set.


Thanks Maxime :slight_smile:
My understanding has got better now.