8 Executing multidocument ACID transactions

 

This chapter covers

  • Understanding the WiredTiger Storage Engine
  • Examining the ACID principles
  • Comparing the Core and Callback APIs
  • Implementing transactions with the Node.js driver
  • Performing transactions using the Python driver
  • Managing transactions with the Ruby driver

Transactions are discrete units of operation within a database management system, comprising multiple related read and write actions. These operations are grouped together and must all succeed as a whole or fail together, ensuring that no partial updates are left in the database. Consider a transaction for booking a travel package that includes a flight and a hotel. If the booking process successfully reserves a flight but encounters a problem with the hotel reservation, the entire transaction must be aborted. This means the flight reservation would also be undone, maintaining the status quo in the database.

Although MongoDB is a nonrelational database and traditionally does not follow the relational model’s approach to transactions, it has long ensured data integrity through its single-document operations. With the introduction of multidocument atomicity, consistency, isolation, and durability (ACID) transactions, however, MongoDB has significantly broadened its applicability and enhanced its capability to handle complex transaction scenarios.

8.1 WiredTiger storage engine

8.1.1 Snapshots and checkpoints

8.1.2 Journaling

8.1.3 Compression

8.1.4 Memory use

8.2 Single-document transaction

8.3 Defining ACID

8.4 Multidocument transactions

8.4.1 Differentiating the Core and Callback APIs

8.4.2 Using transactions with mongosh

8.4.3 Using transactions with the Callback API

8.5 MongoDB transaction considerations

Summary