Skip to main content

Command Palette

Search for a command to run...

What do you mean by Transactions?

Updated
1 min read
What do you mean by Transactions?
R

Full Stack Developer with a passion for building web applications. PHP, Node.js, Laravel, MySQL, MongoDB. Love collaborating & making a difference

For relational databases, transactions ensure data integrity. These are set of instructions that satisfies the conditions of the ACID (atomic, consistent, isolated, and durable) property test. For example, it may require to complete all SQL statements in one go, on failure the entire update can be rolled back.

In MongoDB, an operation on a single document is atomic. Because you can use embedded documents and arrays to capture relationships between data in a single document structure instead of normalizing across multiple documents and collections, this single-document atomicity obviates the need for multi-document transactions for many practical use cases.

For situations that require atomicity of reads and writes to multiple documents (in a single or multiple collections), MongoDB supports multi-document transactions. With distributed transactions, transactions can be used across multiple operations, collections, databases, documents, and shards.

The new callback API works with transactions, which starts a transaction, executes the specified operations, and commits (or aborts on error). The new callback API also incorporates retry logic for TransientTransactionError or UnknownTransactionCommitResult commit errors.

Source:

Transactions — MongoDB Manual. www.mongodb.com/docs/manual/core/transactions.

More from this blog

R

Raja Muhammad Asher - Senior Software Engineer - Full Stack Developer

157 posts

Full Stack Developer with a passion for building web applications. PHP, Node.js, Laravel, ExpressJS, MySQL, MongoDB. Love collaborating & making a difference