@@ -48,31 +48,37 @@ configurable :ref:`sort <node-fundamentals-sort>` and
48
48
49
49
Starting in version 5.7, you can set the ``includeResultMetadata``
50
50
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.
55
59
56
- Suppose a collection contains the following document:
60
+ Suppose a collection contains only the following document:
57
61
58
62
.. code-block:: json
59
63
60
64
{ _id: 1, x: "on" }
61
65
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 :
65
69
66
70
.. code-block:: js
67
71
72
+ // default behavior
68
73
// returns { _id: 1, x: 'on' }
69
- await coll.findOneAndDelete({ x: "on" }, { includeResultMetadata: false } );
74
+ await coll.findOneAndDelete({ x: "on" });
70
75
71
76
// returns { lastErrorObject: { n: 1 }, value: { _id: 1, x: 'on' }, ok: 1, ... }
72
77
await coll.findOneAndDelete({ x: "on" }, { includeResultMetadata: true });
73
78
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" });
76
82
77
83
You can set the ``returnDocument`` setting in the ``options`` object for the
78
84
``findOneAndUpdate()`` and ``findOneAndDelete()`` methods, which lets
0 commit comments