- Reference >
mongo
Shell Methods >- Cursor Methods >
- cursor.readConcern()
cursor.readConcern()¶
On this page
Definition¶
-
cursor.
readConcern
(level)¶ New in version 3.2.
Specify a read concern for the
db.collection.find()
method.The
readConcern()
method has the following form:db.collection.find().readConcern(<level>)
The
readConcern()
method has the following parameter:Parameter Type Description level
string Read concern level.
Possible read concern values are:
"local"
. This is the default read concern level."majority"
. Available for replica sets that use WiredTiger storage engine."linearizable"
. Available for read operations on theprimary
only.
For more formation on the read concern levels, see Read Concern Levels.
Considerations¶
"majority"
Read Concern¶
To use read concern level of "majority"
,
- you must start the
mongod
instances with the--enableMajorityReadConcern
command line option (or thereplication.enableMajorityReadConcern
set totrue
if using a configuration file). - replica sets must use WiredTiger storage engine and election
protocol version 1
.
Read Your Own Writes¶
If using "majority"
or "linearizable"
read concern for read operations, use { w: "majority" }
write concern for write operations on the primary to
ensure that a single thread can read its own writes.
Linearizable Read Concern Performance¶
When specifying linearizable read concern
, always use maxTimeMS()
in case
a majority of data bearing members are unavailable.
db.restaurants.find( { _id: 5 } ).readConcern("linearizable").maxTimeMS(10000)
See also