Skip to content

Commit d720615

Browse files
author
Dave
authored
DOCSP-16178 bump driver bson (#863)
* DOCSP-16178 bump driver bson * DOCSP-16178 bump driver bson * Staging fixes * Review feedback * Staging fixes
1 parent 499fe7d commit d720615

File tree

2 files changed

+131
-159
lines changed

2 files changed

+131
-159
lines changed

source/reference/method/db.collection.findOneAndReplace.txt

Lines changed: 64 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -39,145 +39,130 @@ form:
3939
sort: <document>,
4040
maxTimeMS: <number>,
4141
upsert: <boolean>,
42+
returnDocument: <string>,
4243
returnNewDocument: <boolean>,
4344
collation: <document>
4445
}
4546
)
4647

47-
Parameters and Options
48-
~~~~~~~~~~~~~~~~~~~~~~
48+
Fields and Options
49+
~~~~~~~~~~~~~~~~~~
4950

5051
The :method:`~db.collection.findOneAndReplace()` method takes the following
51-
parameters and options:
52+
fields and options:
5253

5354

5455
.. list-table::
5556
:header-rows: 1
5657
:widths: 20 20 80
5758

58-
* - Parameter
59-
59+
* - Field
6060
- Type
61-
6261
- Description
6362

6463
* - :ref:`filter <findOneAndReplace-filter>`
65-
6664
- document
67-
6865
- .. _findOneAndReplace-filter:
69-
66+
7067
The selection criteria for the update. The same :ref:`query
7168
selectors <query-selectors>` as in the :method:`find()
7269
<db.collection.find()>` method are available.
73-
74-
Specify an empty document ``{ }`` to replace the first document returned in
75-
the collection.
76-
70+
71+
To replace the first document returned in the collection,
72+
specify an empty document ``{ }``.
73+
7774
If unspecified, defaults to an empty document.
78-
79-
Starting in MongoDB 4.2 (and 4.0.12+, 3.6.14+, and 3.4.23+), the operation
80-
errors if the query argument is not a document.
81-
82-
8375

84-
* - :ref:`replacement <findOneAndReplace-replacement>`
76+
Starting in MongoDB 4.2, the operation returns an error if the
77+
query argument is not a document.
8578

79+
* - :ref:`replacement <findOneAndReplace-replacement>`
8680
- document
87-
8881
- .. _findOneAndReplace-replacement:
89-
82+
9083
The replacement document.
91-
84+
9285
Cannot contain
93-
:doc:`update operators</reference/operator/update>`.
94-
95-
The ``<replacement>`` document cannot specify an ``_id`` value that differs
96-
from the replaced document.
97-
98-
86+
:ref:`update operators <update-operators-top-level>`.
9987

100-
* - :ref:`projection <findOneAndReplace-projection>`
88+
The ``<replacement>`` document cannot specify an ``_id`` value
89+
that differs from the replaced document.
10190

91+
* - :ref:`projection <findOneAndReplace-projection>`
10292
- document
103-
10493
- .. _findOneAndReplace-projection:
105-
94+
10695
Optional. A subset of fields to return.
107-
108-
To return all fields in the matching document, omit this parameter.
109-
110-
Starting in MongoDB 4.2 (and 4.0.12+, 3.6.14+, and 3.4.23+), the operation
111-
errors if the projection argument is not a document.
112-
113-
11496

115-
* - :ref:`sort <findOneAndReplace-sort>`
97+
To return all fields in the matching document, omit this
98+
field.
11699

117-
- document
100+
Starting in MongoDB 4.2, the operation returns an error if the
101+
projection field is not a document.
118102

103+
* - :ref:`sort <findOneAndReplace-sort>`
104+
- document
119105
- .. _findOneAndReplace-sort:
120-
121-
Optional. Specifies a sorting order for the documents matched by the ``filter``.
106+
107+
Optional. Specifies a sorting order for the documents matched by
108+
the :ref:`filter <findOneAndReplace-filter>`.
122109

123-
Starting in MongoDB 4.2 (and 4.0.12+, 3.6.14+, and 3.4.23+), the operation
124-
errors if the sort argument is not a document.
110+
Starting in MongoDB 4.2, the operation returns an error if the
111+
sort field is not a document.
125112

126113
See :method:`cursor.sort()`.
127-
128-
129114

130115
* - ``maxTimeMS``
131-
132116
- number
133-
134-
- Optional. Specifies a time limit in milliseconds within which the operation must
135-
complete. Throws an error if the limit is exceeded.
136-
137-
117+
- Optional. Specifies a time limit in milliseconds within which
118+
the operation must complete. Returns an error if the limit is
119+
exceeded.
138120

139121
* - :ref:`upsert <findOneAndReplace-upsert>`
140-
141122
- boolean
142-
143123
- .. _findOneAndReplace-upsert:
144124

145125
.. include:: /includes/extracts/findOneAndReplace-behavior-method.rst
146-
147-
148126

149-
* - :ref:`returnNewDocument <findOneAndReplace-returnNewDocument>`
127+
* - :ref:`returnDocument <findOneAndReplace-returnDocument>`
128+
- string
129+
- .. _findOneAndReplace-returnDocument:
150130

151-
- boolean
131+
Optional. Starting in :binary:`mongosh` 0.13.2,
132+
``returnDocument`` is an alternative for
133+
:ref:`returnNewDocument <findOneAndReplace-returnNewDocument>`.
134+
If both options are set, ``returnDocument`` takes precedence.
152135

136+
``returnDocument: "before"`` returns the original document.
137+
``returnDocument: "after"`` returns the updated document.
138+
139+
* - :ref:`returnNewDocument <findOneAndReplace-returnNewDocument>`
140+
- boolean
153141
- .. _findOneAndReplace-returnNewDocument:
154142

155-
Optional. When ``true``, returns the replacement document instead of the original
156-
document.
157-
143+
Optional. When ``true``, returns the replacement document
144+
instead of the original document.
145+
158146
Defaults to ``false``.
159-
160-
161147

162-
* - :ref:`collation <findOneAndReplace-collation>`
163148

149+
* - :ref:`collation <findOneAndReplace-collation>`
164150
- document
165-
166151
- .. _findOneAndReplace-collation:
167152

168153
Optional.
169-
154+
170155
.. include:: /includes/extracts/collation-option.rst
171-
172-
173156

174157

175158
Returns
176159
~~~~~~~
177160

178-
Returns either the original document or, if :ref:`returnNewDocument:
179-
true <findOneAndReplace-returnNewDocument>`, the replacement document.
180-
161+
Returns the original document by default. Returns the updated document
162+
if :ref:`returnDocument <findOneAndReplace-returnDocument>` is set to
163+
``after`` or :ref:`returnNewDocument
164+
<findOneAndReplace-returnNewDocument>` is set to ``true``.
165+
181166
Behavior
182167
--------
183168

@@ -186,14 +171,14 @@ Document Match
186171

187172
:method:`db.collection.findOneAndReplace()` replaces the first matching
188173
document in the collection that matches the ``filter``.
189-
The ``sort`` parameter can be used to influence which document is modified.
174+
The ``sort`` field can be used to influence which document is modified.
190175

191176
Projection
192177
~~~~~~~~~~
193178

194179
.. include:: /includes/extracts/projection-language-consistency-admonition.rst
195180

196-
The ``projection`` parameter takes a document in the following form:
181+
The ``projection`` field takes a document in the following form:
197182

198183
.. code-block:: javascript
199184

@@ -448,17 +433,17 @@ If the operation exceeds the time limit, it returns:
448433
Replace Document with Upsert
449434
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
450435

451-
The following operation uses the :ref:`upsert <findOneAndReplace-upsert>` field to insert the
452-
replacement document if no document matches the :ref:`filter
453-
<findOneAndReplace-filter>`:
436+
The following operation uses the :ref:`upsert
437+
<findOneAndReplace-upsert>` field to insert the replacement document if
438+
no document matches the :ref:`filter <findOneAndReplace-filter>`:
454439

455440
.. code-block:: javascript
456441

457442
try {
458443
db.scores.findOneAndReplace(
459444
{ "team" : "Fortified Lobsters" },
460445
{ "_id" : 6019, "team" : "Fortified Lobsters" , "score" : 32000},
461-
{ upsert : true, returnNewDocument: true }
446+
{ upsert : true, returnDocument: "after" }
462447
);
463448
} catch (e){
464449
print(e);
@@ -474,8 +459,8 @@ The operation returns the following:
474459
"score" : 32000
475460
}
476461

477-
If ``returnNewDocument`` was false, the operation would return ``null`` as
478-
there is no original document to return.
462+
If ``returnDocument: "before"`` was set, the operation would return
463+
``null`` because there is no original document to return.
479464

480465
Specify Collation
481466
~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)