Query.prototype.readConcern()

Parameters
  • level «String» one of the listed read concern level or their aliases
Returns:
  • «Query» this

Sets the readConcern option for the query.

Example:

  1. new Query().readConcern('local')
  2. new Query().readConcern('l') // same as local
  3. new Query().readConcern('available')
  4. new Query().readConcern('a') // same as available
  5. new Query().readConcern('majority')
  6. new Query().readConcern('m') // same as majority
  7. new Query().readConcern('linearizable')
  8. new Query().readConcern('lz') // same as linearizable
  9. new Query().readConcern('snapshot')
  10. new Query().readConcern('s') // same as snapshot

Read Concern Level:

  1. local MongoDB 3.2+ The query returns from the instance with no guarantee guarantee that the data has been written to a majority of the replica set members (i.e. may be rolled back).
  2. available MongoDB 3.6+ The query returns from the instance with no guarantee guarantee that the data has been written to a majority of the replica set members (i.e. may be rolled back).
  3. majority MongoDB 3.2+ The query returns the data that has been acknowledged by a majority of the replica set members. The documents returned by the read operation are durable, even in the event of failure.
  4. linearizable MongoDB 3.4+ The query returns data that reflects all successful majority-acknowledged writes that completed prior to the start of the read operation. The query may wait for concurrently executing writes to propagate to a majority of replica set members before returning results.
  5. snapshot MongoDB 4.0+ Only available for operations within multi-document transactions. Upon transaction commit with write concern "majority", the transaction operations are guaranteed to have read from a snapshot of majority-committed data.

Aliases

  1. l local
  2. a available
  3. m majority
  4. lz linearizable
  5. s snapshot

Read more about how to use read concern here.