Docs HomeMongoDB Manual

Read Concern "local"

A query with read concern "local" returns data from the instance with no guarantee that the data has been written to a majority of the replica set members (i.e. may be rolled back).

Read concern "local" is the default for read operations against the primary and secondaries.

Regardless of the read concern level, the most recent data on a node may not reflect the most recent version of the data in the system.

Availability

Read concern "local" is available for use with or without causally consistent sessions and transactions.

Read Concern "local" and Transactions

You set the read concern at the transaction level, not at the individual operation level. To set the read concern for transactions, see Transactions and Read Concern.

Starting in MongoDB 4.4, you can create collections and indexes inside a transaction. If explicitly creating a collection or an index, the transaction must use read concern "local". Implicit creation of a collection can use any of the read concerns available for transactions.

Example

Consider the following timeline of a write operation Write 0 to a three member replica set:

Note

For simplification, the example assumes:

  • All writes prior to Write 0 have been successfully replicated to all members.

  • Write prev is the previous write before Write 0.

  • No other writes have occured after Write 0.

Timeline of a write operation to a three member replica set.
TimeEventMost Recent WriteMost Recent w: "majority" write
t 0Primary applies Write 0
Primary: Write 0
Secondary 1: Write prev
Secondary 2: Write prev
Primary: Write prev
Secondary 1: Write prev
Secondary 2: Write prev
t 1Secondary 1 applies write 0
Primary: Write 0
Secondary 1: Write 0
Secondary 2: Write prev
Primary: Write prev
Secondary 1: Write prev
Secondary 2: Write prev
t 2Secondary 2 applies write 0
Primary: Write 0
Secondary 1: Write 0
Secondary 2: Write 0
Primary: Write prev
Secondary 1: Write prev
Secondary 2: Write prev
t 3Primary is aware of successful replication to Secondary 1 and sends acknowledgement to client
Primary: Write 0
Secondary 1: Write 0
Secondary 2: Write 0
Primary: Write 0
Secondary 1: Write prev
Secondary 2: Write prev
t 4Primary is aware of successful replication to Secondary 2
Primary: Write 0
Secondary 1: Write 0
Secondary 2: Write 0
Primary: Write 0
Secondary 1: Write prev
Secondary 2: Write prev
t 5Secondary 1 receives notice (through regular replication mechanism) to update its snapshot of its most recent w: "majority" write
Primary: Write 0
Secondary 1: Write 0
Secondary 2: Write 0
Primary: Write 0
Secondary 1: Write 0
Secondary 2: Write prev
t 6Secondary 2 receives notice (through regular replication mechanism) to update its snapshot of its most recent w: "majority" write
Primary: Write 0
Secondary 1: Write 0
Secondary 2: Write 0
Primary: Write 0
Secondary 1: Write 0
Secondary 2: Write 0

Then, the following tables summarizes the state of the data that a read operation with "local" read concern would see at time T.

Timeline of a write operation to a three member replica set.
Read TargetTime TState of Data
PrimaryAfter t 0Data reflects Write 0.
Secondary 1Before t 1Data reflects Write prev
Secondary 1After t 1Data reflects Write 0
Secondary 2Before t 2Data reflects Write prev
Secondary 2After t 2Data reflects Write 0