4
4
Read Concern
5
5
============
6
6
7
+ .. versionadded:: 3.2
8
+
7
9
.. default-domain:: mongodb
8
10
9
11
.. contents:: On this page
@@ -12,23 +14,23 @@ Read Concern
12
14
:depth: 1
13
15
:class: singlecol
14
16
15
- .. versionchanged:: 3.6
16
-
17
- Add support for :ref:`afterClusterTime` for :readconcern:`"local"`
18
- and :readconcern:`"majority"` read concern level.
19
-
20
17
.. versionchanged:: 3.4
18
+ Adds support for :readconcern:`"linearizable"` read concern level.
21
19
22
- Adds support for :readconcern:`"linearizable"` read concern level.
20
+ .. versionchanged:: 3.6
21
+ Adds support for:
23
22
24
- .. versionadded:: 3.2
23
+ - :readconcern:`"available"` read concern level.
24
+
25
+ - :ref:`afterClusterTime` for :readconcern:`"local"` and
26
+ :readconcern:`"majority"` read concern levels.
25
27
26
28
The ``readConcern`` query option for replica sets and replica set
27
29
shards determines which data to return from a query.
28
30
29
31
.. code-block:: javascript
30
32
31
- readConcern: { level: <"majority"|"local"|"linearizable"> }
33
+ readConcern: { level: <"majority"|"local"|"linearizable"|"available" > }
32
34
readConcern: { level: <"majority"|"local"> , afterClusterTime: <Timestamp> }
33
35
34
36
.. _read-concern-levels:
@@ -47,9 +49,40 @@ The following read concern levels are available:
47
49
48
50
* - .. readconcern:: "local"
49
51
50
- - Default. The query returns the instance's most recent data.
51
- Provides no guarantee that the data has been written to a
52
- majority of the replica set members (i.e. may be rolled back).
52
+ - Default for reads against primary if ``level`` is unspecified
53
+ and for reads against secondaries if ``level`` is unspecified but
54
+ :ref:`afterClusterTime` is specified.
55
+
56
+ The query returns the instance's most recent data. Provides no
57
+ guarantee that the data has been written to a majority of the
58
+ replica set members (i.e. may be rolled back).
59
+
60
+ * - .. readconcern:: "available"
61
+
62
+ - Default for reads against secondaries when
63
+ :ref:`afterClusterTime` and ``level`` are unspecified.
64
+
65
+ The query returns the the instance's most recent data. Provides
66
+ no guarantee that the data has been written to a majority of the
67
+ replica set members (i.e. may be rolled back).
68
+
69
+ For unsharded collections (including collections in a standalone
70
+ deployment or a replica set deployment), :readconcern:`"local"`
71
+ and :readconcern:`"available"` read concerns behave identically.
72
+
73
+ For a sharded cluster, :readconcern:`"available"` read concern
74
+ provides greater tolerance for partitions since it does not wait
75
+ to ensure consistency guarantees. However, a query with
76
+ :readconcern:`"available"` read concern may return orphan
77
+ documents if the shard is undergoing chunk migrations since the
78
+ :readconcern:`"available"` read concern, unlike
79
+ :readconcern:`"local"` read concern, does not contact the
80
+ shard's primary nor the config servers for updated
81
+ :doc:`metadata </core/sharded-cluster-config-servers>`.
82
+
83
+ .. seealso:: :parameter:`orphanCleanupDelaySecs`
84
+
85
+ .. versionadded:: 3.6
53
86
54
87
* - .. readconcern:: "majority"
55
88
@@ -100,13 +133,19 @@ The following read concern levels are available:
100
133
101
134
.. versionadded:: 3.6
102
135
103
- Starting in version 3.6, MongoDB introduces the ``afterClusterTime``
104
- option that can be set by the drivers. Read operations with a specified
105
- ``afterClusterTime`` return data that meets the level requirement and
106
- the specified after cluster time requirement.
136
+ MongoDB introduces the ``afterClusterTime`` option that can be set by
137
+ the drivers. Read operations with a specified ``afterClusterTime``
138
+ return data that meets the level requirement and the specified after
139
+ cluster time requirement.
140
+
141
+ .. important::
142
+
143
+ Do not manually set the ``afterClusterTime``. MongoDB drivers set
144
+ this value automatically for operations associated with
145
+ :ref:`causally consistent sessions <causal-consistency>`.
107
146
108
147
:ref:`Causally consistent sessions<causal-consistency>` use
109
- ``afterClusterTime`` to provide :ref:`causal consistency`.
148
+ ``afterClusterTime`` to provide :ref:`causal consistency <causal-consistency> `.
110
149
111
150
``afterClusterTime`` is available for :readconcern:`"local"` (default)
112
151
and :readconcern:`"majority"` read concern levels:
@@ -115,11 +154,9 @@ and :readconcern:`"majority"` read concern levels:
115
154
116
155
readConcern: { level: <"majority"|"local"> , afterClusterTime: <Timestamp> }
117
156
118
- .. important::
119
-
120
- Do not manually set the ``afterClusterTime``. MongoDB drivers set
121
- this value automatically for operations associated with
122
- :ref:`causally consistent sessions <causal-consistency>`.
157
+ For read operations not associated with causally consistent sessions,
158
+ i.e. the ``afterClusterTime`` is unset, reads against secondary members
159
+ have the default read concern level :readconcern:`"available"`.
123
160
124
161
.. _read-concern-storage-engine-drivers:
125
162
0 commit comments