1.Write concern: acknowledgement and durability
Write concern controls how many replica set members must confirm a write before MongoDB reports it as successful. A weaker write concern returns faster but risks that acknowledged write later being rolled back if the primary fails before it replicates; a stronger one waits longer but makes that outcome far less likely.
Key features
- w: 1 (default in many driver configurations) acknowledges once the primary itself has applied the write — fastest, but a primary failure before replication can lose it
- w: "majority" acknowledges once a majority of voting members have applied it — safe against a single primary failure, because a new primary is elected from that same majority
- w: <n> acknowledges once n members have applied it — a middle ground, but not automatically tied to what an election requires the way "majority" is
- journal (j: true) additionally requires the acknowledging member(s) to have written to their on-disk journal, surviving a process crash and restart on that member
- A stronger write concern trades latency for a lower probability of losing an acknowledged write — never a difference in what gets written, only in when success is reported and how safe that report is
- w: 1
- primary applies the write, acknowledges immediately
- fastest response
- if the primary fails before replicating, the write can be lost on failover
- w: "majority"
- waits for a majority of members to apply it
- higher latency
- safe against single-primary failure — a new primary is elected from that same majority
Command
{ writeConcern: { w: 1 | "majority" | <n>, j: true | false, wtimeout: <ms> } }Write concern trades latency for the durability of an acknowledged write — w: "majority" is safe against a single primary failure because a new primary is always elected from that same majority.