You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Fix grammar and indentation for may-use-secondary commands
* Delete obsolete $out aggregation pipeline operator spec
* Fix RST warnings in CRUD spec
* DRIVERS-823: Support $out and $merge on secondaries
* Suggest clarifying documentation for $merge output cursors
* Clarify setting SecondaryOk/$readPreference for replica sets
* Consolidate $out/$merge tests and add tests for db-aggregate
* Drivers SHOULD use single selection attempt, but MAY use a second
* mongos cannot combine db-aggregate stages with $out or $merge
* Clarify concept of an effective read preference
Co-authored-by: Kevin Albertson <[email protected]>
Copy file name to clipboardExpand all lines: source/crud/crud.rst
+81-4Lines changed: 81 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ Driver CRUD API
12
12
:Status: Approved
13
13
:Type: Standards
14
14
:Minimum Server Version: 2.6
15
-
:Last Modified:August 31, 2021
15
+
:Last Modified:September 28, 2021
16
16
17
17
.. contents::
18
18
@@ -1511,8 +1511,9 @@ Drivers MUST construct a ``WriteConcernError`` from a server reply as follows:
1511
1511
- Set ``message`` to ``writeConcernError.errmsg`` if available.
1512
1512
- Set ``details`` to ``writeConcernError.errInfo`` if available. Drivers MUST NOT parse inside ``errInfo``.
1513
1513
1514
-
See the `Read/Write Concern specification </source/read-write-concern/read-write-concern.rst#writeconcernerror-examples>`_
1515
-
for examples of how a server represents write concern errors in replies.
1514
+
See `writeConcernError Examples </source/read-write-concern/read-write-concern.rst#writeconcernerror-examples>`_
1515
+
in the Read/Write Concern spec for examples of how a server represents write
1516
+
concern errors in replies.
1516
1517
1517
1518
WriteError
1518
1519
~~~~~~~~~~
@@ -1927,8 +1928,83 @@ The ``update`` family of operations require that the update document parameter M
1927
1928
The ``replace`` family of operations require that the replacement document parameter MUST NOT begin with an atomic modifier. In practice, this means that introspection needs to happen on that document to enforce this. However, it is enough to only check the first element in the document. If it does not begin with a ``$`` sign but an element later on does, the server will throw an error.
1928
1929
1929
1930
1931
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1932
+
Aggregation Pipelines with Write Stages
1933
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1934
+
1935
+
This section discusses special considerations for aggregation pipelines that
1936
+
contain write stages (e.g. ``$out``, ``$merge``).
1937
+
1938
+
1939
+
Returning a cursor on the output collection
1940
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1941
+
1942
+
As noted in the documentation for the ``aggregate`` helper earlier in this
1943
+
document, ``$out`` and ``$merge`` are special pipeline stages that cause no
1944
+
results to be returned from the server. As such, drivers MAY setup a cursor to
1945
+
be executed upon iteration against the output collection and return that instead
1946
+
of an iterable that would otherwise have no results.
1947
+
1948
+
Drivers that do so for ``$merge`` MAY remind users that such a cursor may return
1949
+
more documents than were written by the aggregation (e.g. documents that existed
1950
+
in the collection prior to ``$merge`` being executed).
1951
+
1952
+
1953
+
Read preferences and server selection
1954
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1955
+
1956
+
Historically, only primaries could execute an aggregation pipeline with ``$out``
1957
+
or ``$merge``. As of ``featureCompatibilityVersion`` 4.4, secondaries can now
1958
+
execute such pipelines; however, since drivers do not track
1959
+
``featureCompatibilityVersion``, executing an aggregation pipeline with ``$out``
1960
+
or ``$merge`` on a secondary will require a 5.0+ server (i.e. wire version >=
1961
+
13).
1962
+
1963
+
Drivers MUST guarantee the following:
1964
+
1965
+
- If an explicit (i.e. per-operation) read preference is specified for an
1966
+
aggregation with a write stage, drivers MUST attempt to use it. If that would
1967
+
result in a pre-5.0, secondary server being selected, drivers MUST instead
1968
+
select a server using a primary read preference.
1969
+
- If no explicit read preference is specified but a default read preference is
1970
+
available to inherit (e.g. from the Collection), drivers MUST attempt to use
1971
+
it. If that would result in a pre-5.0, secondary server being selected,
1972
+
drivers MUST instead select a server using a primary read preference.
1973
+
1974
+
Drivers SHOULD use a custom server selector to consider server/wire version when
1975
+
matching a read preference and, if a pre-5.0 secondary would be selected, fall
1976
+
back to selecting a primary. With this approach, only a single server selection
1977
+
attempt is needed.
1978
+
1979
+
If it is not possible to augment the server selector and a pre-5.0 secondary is
1980
+
selected, drivers MAY invoke server selection a second time to obtain a primary.
1981
+
However, if the first attempt results in a server selection timeout, drivers
1982
+
MUST NOT make a second attempt and MUST propagate the original timeout error. If
1983
+
the topology type is Single, Sharded, or LoadBalanced, drivers MUST NOT make a
1984
+
second attempt (there is no benefit in doing so).
1985
+
1986
+
Regardless of whether drivers employ a custom server selector or two-attempt
1987
+
approach, they MUST discern the *effective* read preference for the operation,
1988
+
which SHALL be used for specifying the
1989
+
`$readPreference global command argument <../message/OP_MSG.rst#global-command-arguments>`_
1990
+
and
1991
+
`passing read preference to mongos and load balancers <../server-selection/server-selection.rst#passing-read-preference-to-mongos-and-load-balancers>`_
1992
+
(if applicable). The effective read preference SHALL be discerned as follows:
1993
+
1994
+
- In the absence of an explicit or inherited read preference, the effective read
1995
+
preference is ``{ "mode": "primary" }``.
1996
+
- If an explicit or inherited read preference results in selection of an
1997
+
ineligible server and selection falls back to a primary, the effective read
1998
+
preference is ``{ "mode": "primary" }``.
1999
+
- If a pre-5.0 mongos or a load balancer backing a pre-5.0 mongos is selected,
2000
+
the effective read preference is ``{ "mode": "primary" }``.
2001
+
- If an explicit or inherited read preference is used and results in selection
2002
+
of an eligible server (excluding a pre-5.0 mongos as discussed above), that is
2003
+
the effective read preference.
2004
+
2005
+
1930
2006
Test Plan
1931
-
======================================
2007
+
=========
1932
2008
1933
2009
See the `README <tests/README.rst>`_ for tests.
1934
2010
@@ -2024,6 +2100,7 @@ Q: Why are client-side errors raised for some unsupported options?
2024
2100
Changes
2025
2101
=======
2026
2102
2103
+
* 2021-09-28: Support aggregations with $out and $merge on 5.0+ secondaries
2027
2104
* 2021-08-31: Allow unacknowledged hints on write operations if supported by server (reverts previous change).
2028
2105
* 2021-06-02: Introduce WriteError.details and clarify WriteError construction
0 commit comments