Chapter 8. Transactions
Transactions are logical groups of processing in a database, and 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
Introduction to Transactions
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.
Note
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.
A Definition of ACID
ACID is the accepted set of properties a transaction must meet to be a “true” transaction. ACID is an acronym ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access