Skip to content

Commit 6dc838e

Browse files
author
Sam Kleinman
committed
DOCS-957: clarification behavior on upserts that turn into inserts
1 parent b588599 commit 6dc838e

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

source/reference/command/findAndModify.txt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,26 @@ findAndModify
9595
Optional. Used in conjunction with the ``update`` field. When
9696
``true``, the :dbcommand:`findAndModify` command creates a
9797
new document if the ``query`` returns no documents. The
98-
default is ``false``. In version 2.2, the
99-
:dbcommand:`findAndModify` command returns ``null`` when
100-
``upsert`` is ``true``.
98+
default is ``false``.
10199

102100
.. code-block:: javascript
103101

104102
upsert: <boolean>
105103

104+
If you specify ``{ new: false }`` and the upsert operation
105+
performs an insert operation, then the operation will return
106+
a document that resembles the following:
107+
108+
.. code-block:: javascript
109+
110+
{ 'ok': 1.0, 'value': null }
111+
112+
106113
.. versionchanged:: 2.2
107-
Previously, ``upsert`` operations returned a an empty
108-
document (e.g. ``{ }``,) see :ref:`the 2.2 release notes
109-
<2.2-findandmodify-returns-null>` for more information.
114+
Previously, ``upsert`` operations that performed inserts
115+
returned an empty document (e.g. ``{ }``,) see :ref:`the
116+
2.2 release notes <2.2-findandmodify-returns-null>` for
117+
more information.
110118

111119
Consider the following example:
112120

source/release-notes/2.2.txt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -265,21 +265,22 @@ If your cluster runs with authentication:
265265

266266
.. _2.2-findandmodify-returns-null:
267267

268-
``findAndModify`` Returns Null Value for Upserts
269-
````````````````````````````````````````````````
268+
``findAndModify`` Returns Null Value for Upserts that Perform Inserts
269+
`````````````````````````````````````````````````````````````````````
270270

271-
In version 2.2, for :term:`upsert` operations, :dbcommand:`findAndModify`
272-
commands will now return the following output:
271+
In version 2.2, for :term:`upsert` that perform inserts,
272+
:dbcommand:`findAndModify` commands will now return the following
273+
output:
273274

274275
.. code-block:: javascript
275276

276-
{'ok': 1.0, 'value': null}
277+
{ 'ok': 1.0, 'value': null }
277278

278-
In the :program:`mongo` shell, :dbcommand:`findAndModify` operations
279-
running as upserts will only output a ``null`` value.
279+
In the :program:`mongo` shell, upsert :dbcommand:`findAndModify`
280+
operations that perform inserts only output a ``null`` value.
280281

281-
Previously, in version 2.0 these operations would return an empty
282-
document, e.g. ``{ }``.
282+
In version 2.0 these operations would return an empty document,
283+
e.g. ``{ }``.
283284

284285
See: :issue:`SERVER-6226` for more information.
285286

0 commit comments

Comments
 (0)