0PricingLogin
MongoDB Academy · Lesson

Write Concerns and Acknowledged Durability

Learners will configure w:majority, w:1, and journaling options to tune the durability guarantee of write operations.

What Is a Write Concern?

A write concern tells MongoDB how many replica set members must acknowledge a write before the driver considers it successful. It is the primary knob for trading durability (more acknowledgements = safer) against latency (fewer acknowledgements = faster). Every write operation — insert, update, delete, or replace — can specify its own write concern.

The w Option: Counting Acknowledgements

The w field controls how many members must confirm the write. w: 0 means fire-and-forget (no acknowledgement at all). w: 1 (default) means only the primary must confirm. w: 2 means the primary plus one secondary. w: 'majority' is the recommended production setting — it waits for a majority of voting members to confirm.

// w:1 — only primary acknowledges (default)
db.orders.insertOne({ item: 'pen' }, { writeConcern: { w: 1 } })

// w:majority — safe for production
db.orders.insertOne({ item: 'pen' }, { writeConcern: { w: 'majority' } })

All lessons in this course

  1. Replica Set Members: Primary, Secondary, Arbiter
  2. Elections and Automatic Failover
  3. Write Concerns and Acknowledged Durability
  4. Read Preferences: Distributing Read Load
← Back to MongoDB Academy