Docs Home → Develop Applications → MongoDB Manual
Default MongoDB Read Concerns/Write Concerns
Read Concern
Default Read Concern
The default read concern is as follows:
Operations | Default Read Concern |
---|---|
Reads against primary | Note
|
Reads against secondaries. | Note
|
Specify Read Concern: MongoDB Drivers
Additional Information
For more information on the available read concerns, see Read Concern.
Write Concern
Default Write Concern
Starting in MongoDB 5.0, the implicit default
write concern is
w: majority
. However, special
considerations are made for deployments containing
arbiters:
The voting majority of a replica set is 1 plus half the number of voting members, rounded down. If the number of data-bearing voting members is not greater than the voting majority, the default write concern is
{ w: 1 }
.In all other scenarios, the default write concern is
{ w: "majority" }
.
Specifically, MongoDB uses the following formula to determine the default write concern:
if [ (#arbiters > 0) AND (#non-arbiters <= majority(#voting-nodes)) ] defaultWriteConcern = { w: 1 } else defaultWriteConcern = { w: "majority" }
For example, consider the following deployments and their respective default write concerns:
Non-Arbiters | Arbiters | Voting Nodes | Majority of Voting Nodes | Implicit Default Write Concern |
---|---|---|---|---|
2 | 1 | 3 | 2 | { w: 1 } |
4 | 1 | 5 | 3 | { w: "majority" } |
In the first example:
There are 2 non-arbiters and 1 arbiter for a total of 3 voting nodes.
The majority of voting nodes (1 plus half of 3, rounded down) is 2.
The number of non-arbiters (2) is equal to the majority of voting nodes (2), resulting in an implicit write concern of
{ w: 1 }
.
In the second example:
There are 4 non-arbiters and 1 arbiter for a total of 5 voting nodes.
The majority of voting nodes (1 plus half of 5, rounded down) is 3.
The number of non-arbiters (4) is greater than the majority of voting nodes (3), resulting in an implicit write concern of
{ w: "majority" }
.
Specify Write Concern: MongoDB Drivers
Additional Information
For more information on the available write concerns, see Write Concern.
Causally Consistency Guarantees
With causally consistent client sessions, the client sessions only guarantee causal consistency if:
the associated read operations use
"majority"
read concern, andthe associated write operations use
"majority"
write concern.