Navigation
  • Reference >
  • Default MongoDB Read Concerns/Write Concerns

Default MongoDB Read Concerns/Write Concerns

Read Concern

Read/Write Concern Inheritance

Default Read Concern

The default read concern is as follows:

Operations Default Read Concern
Reads against primary

"local"

Note

  • This read concern can return data that may be rolled back.
  • This read concern does not guarantee causal consistency.
Reads against secondaries if the reads are

"local"

Note

  • This read concern can return data that may be rolled back.
  • This read concern does not guarantee causal consistency.
Reads against secondaries if the reads are not

"available"

Note

  • This read concern can return data that may be rolled back.
  • This read concern does not guarantee causal consistency.
  • For sharded collections, this read concern can also return orphaned documents.

Specify Read Concern: MongoDB Drivers

Note

The following applies to operations issued outside transactions.

For read concern information related to operations issued inside transactions, click on the Operations in Transactions tab.

Using the MongoDB drivers, you can override the default read concern and set read concern for operations at the following levels:

Level Description
Client level Applies to operations unless a finer-grained read concern for an operation is set at the database/collection/operation level.
Database level

Applies to operations on the database’s collections (i.e. overrides the client read concern) unless a read concern has been set at the collection level or the operation level.

Note

Does not apply to operations inside transactions.

Collection level

Applies for read operations on the collection (i.e. overrides the database/client read concern) unless a read concern has been set at the operation level.

Note

Does not apply to operations inside transactions.

Operation level

Applies for the specific read operation (i.e. overrides the database/client/collection read concern).

The ability to set read concern at the operation depends on the driver. Refer to your driver’s documentation.

Note

Does not apply to operations inside transactions.

Note

The following applies to operations issued inside transactions.

For read concern information related to operations issued outside transactions, click on the Operations outside Transactions tab.

Using the MongoDB drivers, you can override the default read concern and set read concern for transactions at the following levels:

Level Description
Client level

Applies to transactions unless a finer-grained read concern is set at the session/transaction level.

Note

All operations in a transaction use the transaction read concern; i.e., any read concern set at the operation/collection/database level is ignored inside the transaction.

Session level

Applies to transactions started in the session (i.e. overrides the client read concern) unless a finer-grained read concern level is set at a specific transaction level.

Note

All operations in a transaction use the transaction read concern; i.e., any read concern set at the operation/collection/database level is ignored inside the transaction.

See Transactions and Read Concern for more information.

Transaction level

Applies to the specific transaction (i.e. overrides the client/session read concern).

Note

All operations in a transaction use the transaction read concern; i.e., any read concern set at the operation/collection/database level is ignored inside the transaction.

See Transactions and Read Concern for more information.

Additional Information

For more information on the available read concerns, see Read Concern.

Write Concern

Read/Write Concern Inheritance

Default Write Concern

The default write concern is w: 1.

Note

  • With the default write concern, data can be rolled back.
  • This write concern does not guarantee causal consistency.

Specify Write Concern: MongoDB Drivers

Note

The following applies to operations issued outside transactions.

For read concern information related to operations issued inside transactions, click on the Operations in Transactions tab.

Using the MongoDB drivers, you can override the default write concern and set write concern for operations at the following levels:

Level Description
Client level Applies to operations unless a finer-grained write concern for an operation is set at the operation/database/collection.
Database level

Applies to write operations on the database’s collections (i.e. overrides the client write concern) unless a write concern has been set at the collection level or the operation level.

Note

Does not apply to operations inside transactions.

Collection level

Applies to write operations on the collection (i.e. overrides the database and client write concern) unless a write concern has been set at the operation level.

Note

Does not apply to operations inside transactions.

Operation level

Applies to the specific write operation.

The ability to set write concern at the operation depends on the driver. Refer to your driver’s documentation.

Note

Does not apply to operations inside transactions.

Note

The following applies to operations issued inside transactions.

For read concern information related to operations issued outside transactions, click on the Operations outside Transactions tab.

Using the MongoDB drivers, you can override the default write concern and set write concern for for transactions at the following levels:

Level Description
Client level

Applies to transactions unless a finer-grained write concern for transactions are set at the session/transaction level.

Transaction write concern applies to the commit operation and the operations inside the transaction.

Note

All operations within a transaction use the transaction write concern; i.e., any write concern set at the operation/collection/database level is ignored inside the transaction.

Session level

Applies for transactions started in the session unless the write concern level is set at a specific transaction level.

Transaction write concern applies to the commit operation and the operations inside the transaction.

Note

All operations within a transaction use the transaction write concern; i.e., any write concern set at the operation/collection/database level is ignored inside the transaction.

Transaction level

Applies to the specific transaction.

Transaction write concern applies to the commit operation and the operations inside the transaction.

Note

All operations within a transaction use the transaction write concern; i.e., any write concern set at the operation/collection/database level is ignored inside the transaction.

See Transactions and Write Concern for more information.

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, and
  • the associated write operations use "majority" write concern.