Explorer
MongoDB

Write Concern and Read Concern

Write Concern & Read Concern

MongoDB allows developers to tune data consistency, durability, and latency per operation using Write Concern and Read Concern.

Write Concern Levels

Write Concern (w) Acknowledgment Point Durability Guarantee
w: 0 (Unacknowledged) Socket write issued; no server acknowledgment Fire-and-forget; highest throughput, potential data loss
w: 1 (Default) Acknowledged by Primary node only Data can be lost if primary crashes before replicating to secondaries
w: "majority" Committed to memory by a majority of replica set nodes Guaranteed against rollback upon primary election
j: true (Journaled) Committed to on-disk journal file Survives complete power outage of the host server

Read Concern Levels

Read Concern Level Data Returned Rollback Safety
"local" (Default) Returns node's most recent local data May be rolled back if primary steps down
"majority" Returns data acknowledged by a majority of nodes Will never be rolled back
"linearizable" Verifies with majority in real-time before returning Prevents stale reads from partitioned nodes; highest latency
"snapshot" Returns snapshot at transaction start Full multi-document transaction isolation

Finished this lesson?

Mark this chapter complete to update your learning streak and unlock the next lesson.