Skip to content
This repository was archived by the owner on Aug 20, 2019. It is now read-only.

Commit c449aee

Browse files
committed
trivial: wording tweak to findAndModify
1 parent 6482338 commit c449aee

File tree

4 files changed

+42
-25
lines changed

4 files changed

+42
-25
lines changed
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
ref: _fact-findandmodify-return
22
content: |
3-
If the ``new`` parameter is not set or is ``false``:
3+
- If the ``new`` parameter is not set or is ``false``:
44
5-
- the pre-modification document if the query matcches a document,
5+
- the pre-modification document if the query matches a document;
66
7-
- otherwise, ``null``.
7+
- otherwise, ``null``.
88
9-
If ``new`` is ``true``:
9+
- If ``new`` is ``true``:
1010
11-
- the modified document if the query returns a match,
11+
- the modified document if the query returns a match;
1212
13-
- the inserted document if ``upsert: true`` and no document matches the query,
13+
- the inserted document if ``upsert: true`` and no document matches the query;
1414
15-
- otherwise, ``null``.
15+
- otherwise, ``null``.
1616
17-
Prior to MongoDB 3.0, if ``new`` is not set or is ``false``, ``upsert: true``,
18-
and there is a ``sort`` term, then {{op}} would yield an empty document
19-
``{}`` instead of ``null``.
17+
.. versionchanged:: 3.0
18+
19+
In previous versions, if for the update, ``sort`` is specified,
20+
and ``upsert: true``, and the ``new`` option is not set or ``new:
21+
false``, {{op}} instead of ``null``.
2022
---
2123
ref: fact-findandmodify-command-return
2224
inherit:
2325
file: extracts-fact-findandmodify-return.yaml
2426
ref: _fact-findandmodify-return
2527
replacement:
26-
op: :dbcommand:`findAndModify`
28+
op: ":dbcommand:`findAndModify` returns an empty document ``{}`` in the ``value`` field"
2729
---
2830
ref: fact-findandmodify-method-return
2931
inherit:
3032
file: extracts-fact-findandmodify-return.yaml
3133
ref: _fact-findandmodify-return
3234
replacement:
33-
op: :method:`db.collection.findAndModify()`
35+
op: ":method:`db.collection.findAndModify()` returns an empty document ``{}``"
3436
...

source/reference/command/findAndModify.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ Definition
4343
Output
4444
------
4545

46-
The return document contains the following fields:
46+
The :dbcommand:`findAndModify` command returns a document with the
47+
following fields:
4748

4849
.. include:: /includes/apiargs/dbcommand-findAndModify-return.rst
4950

@@ -61,7 +62,12 @@ The ``lastErrorObject`` embedded document contains the following fields:
6162
``value``
6263
~~~~~~~~~
6364

64-
The ``value`` embedded document contains the following:
65+
For ``remove`` operations, ``value`` contains the removed document if
66+
the query matches a document. If the query does not match a document to
67+
remove, ``value`` contains ``null``.
68+
69+
For ``update`` operations, the ``value`` embedded document contains the
70+
following:
6571

6672
.. include:: /includes/extracts/fact-findandmodify-command-return.rst
6773

@@ -324,8 +330,8 @@ The command returns the newly inserted document in the ``value`` field:
324330
"_id" : ObjectId("54f62bbfc85d4472eadea26d"),
325331
"name" : "Pascal",
326332
"rating" : 25,
327-
"state" : "active"
328-
"score" : 1,
333+
"state" : "active",
334+
"score" : 1
329335
},
330336
"ok" : 1
331337
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ Definition
4545
Return Data
4646
-----------
4747

48-
The :method:`~db.collection.findAndModify()` method returns one of the
49-
following:
48+
For remove operations, if the query matches a document,
49+
:method:`~db.collection.findAndModify()` returns the removed document.
50+
If the query does not match a document to remove,
51+
:method:`~db.collection.findAndModify()` returns ``null``.
52+
53+
For update operations, :method:`~db.collection.findAndModify()` returns
54+
one of the following:
5055

5156
.. include:: /includes/extracts/fact-findandmodify-method-return.rst
5257

source/release-notes/3.0-compatibility.txt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,17 @@ General Compatibility Changes
467467
``findAndModify`` Return Document
468468
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
469469

470-
In MongoDB 3.0, the return document of the :dbcommand:`findAndModify` command
471-
has changed when executing ``update`` operatons where the ``query``
472-
matches no document, ``upsert: true``, and ``new: false``.
473-
474-
Now the return document's ``value`` field will always contain ``null`` in this
475-
case. Previously, it would instead contain an empty document ``{}`` if the
476-
arguments included a ``sort`` term.
470+
In MongoDB 3.0, when performing an update with
471+
:dbcommand:`findAndModify` that also specifies ``upsert: true`` *and*
472+
either the ``new`` option is not set or ``new: false``,
473+
:dbcommand:`findAndModify` returns ``null`` in the ``value`` field if
474+
the ``query`` does not match any document, regardless of the ``sort``
475+
specification.
476+
477+
In previous versions, :dbcommand:`findAndModify` returns an empty
478+
document ``{}`` in the ``value`` field if a ``sort`` is specified for
479+
the update, and ``upsert: true``, and the ``new`` option is not set or
480+
``new: false``.
477481

478482
``upsert:true`` with a Dotted ``_id`` Query
479483
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)