Skip to content

Commit 4876d6f

Browse files
rustagirmongoKart
authored andcommitted
DOCSP-31807: includeResultMetadata option behavior changes for findOneAnd... methods (mongodb#750)
* DOCSP-31807: includeResultMetadata option behavior changes * MW PR fixes 1 * small fixes * MW suggestion
1 parent 02fdbba commit 4876d6f

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

source/fundamentals/crud/compound-operations.txt

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,37 @@ configurable :ref:`sort <node-fundamentals-sort>` and
4848

4949
Starting in version 5.7, you can set the ``includeResultMetadata``
5050
setting in the ``options`` object to specify the return type for each
51-
of these methods. The setting defaults to ``true``, which means the
52-
method returns a ``ModifyResult`` type. If you set
53-
``includeResultMetadata`` to ``false``, the method returns the
54-
modified document.
51+
of these methods.
52+
53+
Starting in version 6.0, this setting defaults to ``false``, which
54+
means that each method returns the matched document, or, if no
55+
document is matched, it returns ``null``. If you set
56+
``includeResultMetadata`` to ``true``, the method returns a
57+
``ModifyResult`` type that contains the found document and additional
58+
metadata.
5559

56-
Suppose a collection contains the following document:
60+
Suppose a collection contains only the following document:
5761

5862
.. code-block:: json
5963

6064
{ _id: 1, x: "on" }
6165

62-
The following code shows the return type for ``findOneAndDelete()``
63-
operations when ``includeResultMetadata`` is set to ``true`` and
64-
``false``:
66+
The following code shows how the value of the
67+
``includeResultMetadata`` option changes the return type of
68+
the ``findOneAndDelete()`` method:
6569

6670
.. code-block:: js
6771

72+
// default behavior
6873
// returns { _id: 1, x: 'on' }
69-
await coll.findOneAndDelete({ x: "on" }, { includeResultMetadata: false });
74+
await coll.findOneAndDelete({ x: "on" });
7075

7176
// returns { lastErrorObject: { n: 1 }, value: { _id: 1, x: 'on' }, ok: 1, ... }
7277
await coll.findOneAndDelete({ x: "on" }, { includeResultMetadata: true });
7378

74-
// no document matched, returns null
75-
await coll.findOneAndDelete({ x: "off" }, { includeResultMetadata: false });
79+
// no document matched
80+
// returns null
81+
await coll.findOneAndDelete({ x: "off" });
7682

7783
You can set the ``returnDocument`` setting in the ``options`` object for the
7884
``findOneAndUpdate()`` and ``findOneAndDelete()`` methods, which lets

source/upgrade.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ Version 6.x Breaking Changes
100100
- If you start a session on a client, then pass that session to a
101101
different client, the driver throws an error when you
102102
perform any operations in the session.
103+
- The ``includeResultMetadata`` option for compound operation methods is
104+
``false`` by default.
103105

104106
.. _node-breaking-changes-v5.x:
105107

source/whats-new.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ What's New in 6.0
8484
- If you start a session on a client, then pass that session to a
8585
different client, the driver throws an error when you
8686
perform any operations in the session.
87+
88+
- The ``includeResultMetadata`` option for compound operation methods
89+
is ``false`` by default. See the :ref:`Built-in
90+
Methods <node-compound-operations-builtin>` section of the Compound
91+
Operations guide for more information.
8792

8893
The {+driver-short+} v6.0 release includes the following features:
8994

@@ -199,11 +204,12 @@ The {+driver-short+} v5.7 release includes the following features:
199204
instead, see the Legacy SSL options deprecated section in the
200205
v5.7.0 Release Highlights linked at the end of this section.
201206

202-
- A new option for ``findOneAnd...`` compound methods. The ``includeResultMetaData``
207+
- A new option for compound operation methods. The
208+
``includeResultMetaData``
203209
option allows you to specify whether to include information about the
204-
operation result. See the
205-
:ref:`Compound Operations Built-in Methods <node-compound-operations-builtin>`
206-
section for more information.
210+
operation result. See the :ref:`Built-in Methods
211+
<node-compound-operations-builtin>` section of the Compound Operations
212+
guide for more information.
207213

208214
- Support for change stream split events which enables processing change
209215
stream documents that exceed the 16MB maximum BSON size limit.

0 commit comments

Comments
 (0)