← MongoDB learning path
MongoDB · Module 8 of 10

Transactions and consistency

Keep related changes safe together.

📖 Key ideas

  1. Single-document writes are atomic.
  2. Multi-document transactions work on replica sets.
  3. Use sessions: startSession, withTransaction.
  4. Write concern controls how many nodes confirm a write.
  5. Read concern controls the consistency of reads.
💡 Real-life example: A transaction is a bank transfer: both debit and credit happen, or neither does.
AtomicAll or nothing
TransactionGroup of operations committed together
Write concernAcknowledgement level for writes
SessionContext for a transaction