Best practices
There are several best practices to help make your work with transactions simpler. This section will give a brief overview of these practices.
Generally, you can avoid multi-document ACID transactions by using rich document models through a careful process of data modeling. The modeling phase can help you avoid using transactions altogether, and in many cases, this is always something to keep in mind. However, if your application requires the use of transactions, they integrate seamlessly into your non-transactional workflow, but should be subject to some particular considerations.
As stated previously, transactions have a default maximum time limit set to 60 seconds. This value can be increased by modifying the transactionLifetimeLimitSeconds
server parameter at the mongod
level. If you're working with a sharded cluster, this parameter must be set on all shard replica members. After this period has expired, as you've seen in the example, the transaction...