liveBook · Manning

Read concern

As explained in MongoDB 8.0 in Action, Third Edition

Read concern is a MongoDB setting that specifies the consistency and visibility guarantees for data returned by read operations.

Read concern is a MongoDB setting that controls the consistency and isolation of data returned by read operations. It balances consistency, performance, and availability across replica sets and sharded clusters. section 9.5 section 9.5.2

Choose a level according to the application’s tolerance for stale, unavailable, or slower reads:

  • local (default) reads from the current instance without waiting for replication; fast results may later be rolled back. section 9.5.2
  • available minimizes latency and consistency guarantees, making it useful when availability matters more than accuracy, especially in sharded clusters. section 9.5.2
  • majority returns data acknowledged by most replica set members, supporting durable reads that withstand node failures. section 9.5.2
  • linearizable provides the strictest consistency by confirming that previous majority-acknowledged writes have been applied, with possible performance overhead. section 9.5.2
  • snapshot reads a point-in-time view of majority-committed data across the cluster, which is useful in multidocument transactions. section 9.5.2

Read majority-confirmed data

Apply a read concern to a cursor when a query should return data confirmed by a majority of replica set members: db.routes.find({ src_airport: 'MUC' }).readConcern('majority').

For applications that read their own writes on the primary, pair majority read concern with { w: 'majority' } write concern. Read preference separately determines whether reads target primary or secondary members. section 9.5 section 9.6

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Defines five levels and demonstrates cursor and global configuration, but does not detail command syntax beyond supplied examples.
Examples
Uses a majority-confirmed cursor query and global setDefaultRWConcern configuration.
What it assumes
Assumes familiarity with MongoDB queries, replica-set members, write concern, and read preference.
What you can do after
Apply it via cursor or global configuration to select consistency guarantees appropriate for application reads.
How it connects
Connects read concern with write concern, read preference, replica sets, sharded clusters, and multidocument transactions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.