← MongoDB learning pathMongoDB · Module 8 of 10
Transactions and consistency
Keep related changes safe together.
📖 Key ideas
- Single-document writes are atomic.
- Multi-document transactions work on replica sets.
- Use sessions: startSession, withTransaction.
- Write concern controls how many nodes confirm a write.
- 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