-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
read-concern.txt
108 lines (71 loc) · 3.02 KB
/
read-concern.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
============
Read Concern
============
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
.. versionadded:: 3.2
MongoDB 3.2 introduces the ``readConcern`` query option for replica
sets and replica set shards. By default, MongoDB uses a read concern of
``"local"`` to return the most recent data available to the MongoDB
instance at the time of the query, even if the data has not been
persisted to a majority of replica set members and may be rolled back.
Storage Engine and Drivers Support
----------------------------------
For the :doc:`WiredTiger storage engine </core/wiredtiger>`, the
``readConcern`` option allows clients to choose a level of isolation
for their reads. You can specify a read concern of ``"majority"`` to
read data that has been written to a majority of replica set members
and thus cannot be rolled back.
With the :doc:`MMAPv1 storage engine </core/mmapv1>`, you can only
specify a ``readConcern`` option of ``"local"``.
.. tip::
The :dbcommand:`serverStatus` command returns the
:serverstatus:`storageEngine.supportsCommittedReads` field which
indicates whether the storage engine supports ``"majority"`` read
concern.
``readConcern`` requires MongoDB drivers updated for 3.2.
Read Concern Levels
-------------------
By default, MongoDB uses a ``readConcern`` of ``"local"`` which
does not guarantee that the read data would not be rolled back.
You can specify a ``readConcern`` of ``"majority"`` to read data that
has been written to a majority of replica set members and thus cannot be
rolled back.
.. list-table::
:header-rows: 1
:widths: 10 90
* - ``level``
- Description
* - .. readconcern:: "local"
- Default. The query returns the instance's most recent copy of
data. Provides no guarantee that the data has been written to a
majority of the replica set members.
* - .. readconcern:: "majority"
- The query returns the instance's most recent copy of data
confirmed as written to a majority of members in the replica set.
.. include:: /includes/fact-enable-majority-readConcern.rst
.. include:: /includes/usage-read-concern-majority.rst
.. include:: /includes/fact-readConcern-most-recent-data-in-node.rst
``readConcern`` Option
----------------------
Use the ``readConcern`` option to specify the read concern level.
.. code-block:: javascript
readConcern: { level: <"majority"|"local"> }
For the ``level`` field, specify either the string ``"majority"`` or
``"local"``.
The ``readConcern`` option is available for the following operations:
- :dbcommand:`find` command
- :dbcommand:`aggregate` command and the
:method:`db.collection.aggregate()` method
- :dbcommand:`distinct` command
- :dbcommand:`count` command
- :dbcommand:`parallelCollectionScan` command
- :dbcommand:`geoNear` command
- :dbcommand:`geoSearch` command
To specify the read concern for the :binary:`~bin.mongo` shell method
:method:`db.collection.find()`, use the :method:`cursor.readConcern()`
method.