Catalog My learning Blog
MongoDB Tutorial: Schema Design, Indexing and Sharding · Phase 4 · Lesson 21 · 2 min read

MongoDB Read Concern and Write Concern Explained

On this page
  1. Read concern vs write concern
  2. Write concern levels
  3. Read concern levels
  4. Reading your own writes with causal consistency
  5. Choosing read and write concerns per data type
  6. Check yourself

Read concern vs write concern

Every write and read on a replica set answers two questions:

  • Write concern: how many members must have this write before I'm told it succeeded?
  • Read concern: what guarantee must the data I read have: any version, or one that can never be rolled back?

Stronger settings mean safer data and higher latency. MongoDB lets you choose per operation.

Write concern levels

Write concernAcknowledged whenCan be rolled back?
w: 0Not acknowledged at allYou won't even know it failed
w: 1The primary applied itYes, if the primary fails before replicating
w: "majority" (default since 5.0)A majority of voting members have itNo
w: <n>n members have itDepends on n

Options:

  • j: true: members also wrote it to their on-disk journal before acknowledging. With majority write concern, journaling is the default behavior.
  • wtimeout: stop waiting after N milliseconds and return an error. The write may still complete later; a timeout doesn't undo it.
JavaScript
db.orders.insertOne({ _id: 991, total: NumberDecimal("48.00") }, { writeConcern: { w: "majority", wtimeout: 5000 } })

Read concern levels

Read concernReturns
local (default for most reads)The member's most recent data, which might later be rolled back
availableLike local; on sharded clusters may return orphaned documents during migrations
majorityOnly data acknowledged by a majority: never rolled back
linearizableMajority data that reflects all writes acknowledged before the read began; primary only, slow
snapshotA consistent point-in-time view; used in transactions (Day 18)
Write concern decides how many members confirm a write; read concern decides whether a read may see data that hasn't reached a majority yet.
Write concern decides how many members confirm a write; read concern decides whether a read may see data that hasn't reached a majority yet.

Reading your own writes with causal consistency

A user updates their profile (majority write) and the next request reads from a secondary that hasn't caught up: they see the old profile. Causally consistent sessions fix this: within a session, MongoDB guarantees each read reflects the session's earlier writes, even on secondaries, by waiting for the member to catch up:

Code
with client.start_session(causal_consistency=True) as s:
    profiles.update_one({"_id": 42}, {"$set": {"name": "Sam"}}, session=s)
    profiles.with_options(read_preference=ReadPreference.SECONDARY_PREFERRED,
                          read_concern=ReadConcern("majority")).find_one({"_id": 42}, session=s)

Causal guarantees require majority read and write concerns.

Choosing read and write concerns per data type

DataWriteRead
Orders, payments, accountsmajoritymajority for anything that triggers actions
User profile editsmajorityCausal session, or primary
Click and log eventsw: 1 acceptable for throughputlocal
Analytics on secondaries(n/a)local or majority, stale reads acceptable

Keep the default majority write concern unless you've measured a need and accepted the loss risk. Deliberately lowering it for bulk, low-value data is fine; lowering it globally is how teams lose orders during a failover.

Check yourself

A majority-acknowledged write exists on most members and survives any failover; a w: 1 write can be rolled back if the primary fails before replicating it.

No. The server stopped waiting for replication, but the write was applied on the primary and may still replicate and become durable. Treat the outcome as unknown, and check or retry idempotently instead of assuming it failed.

Use a causally consistent session with majority read and write concerns, so a read waits until the secondary has caught up with that session's writes, or read that user's data from the primary right after they change it.

The read returns only data acknowledged by a majority of members, which can't be rolled back by a failover. It may be slightly older than the primary's latest writes.

Often w: 1, since losing a few events in a rare failover is acceptable and latency matters. Orders and payments should use w: "majority".