Transactions are logical groups of processing in a database, each group or transaction can contain one or more operations such as reads and/or writes across multiple documents. MongoDB supports ACID compliant transactions across multiple operations, collections, databases, documents, and shards. In this chapter, we introduce transactions, define what ACID means for a database, highlight how you use these in your applications, and provide tips for tuning transactions in MongoDB. We will cover:
What a transaction is
How to use transactions
Tuning transaction limits for your application
As we mentioned above, a transaction is a logical unit of processing in a database that includes one or more database operations, which can be read or write operations. There are situations where your application may require reads and writes to multiple documents (in one or more collections) as part of this logical unit of processing. An important aspect of a transaction is that it is never partially completed, it either succeeds or fails.
In order to use transactions, your MongoDB deployment must be on MongoDB version 4.2 or later and your MongoDB drivers must be updated for MongoDB 4.2 or later. MongoDB provides a Driver Compatibility Reference page that you can use to ensure your MongoDB Driver version is compatible.
ACID is the accepted set of properties a transaction must meet to be a `true` transaction. ACID is an acronym ...