Skip to content

Fix the returnOriginal param in the findOneAndUpdate #2749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions source/reference/method/db.collection.findOneAndUpdate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Definition
.. method:: db.collection.findOneAndUpdate( filter, update, options )

.. versionadded:: 3.2
Updates a single document based on the ``filter`` and

Updates a single document based on the ``filter`` and
``sort`` criteria.
The :method:`~db.collection.findOneAndUpdate()` method has the following

The :method:`~db.collection.findOneAndUpdate()` method has the following
form:

.. code-block:: javascript
Expand All @@ -33,7 +33,7 @@ Definition
sort: <document>,
maxTimeMS: <number>,
upsert: <boolean>,
returnNewDocument: <boolean>,
returnOriginal: <boolean>,
collation: <document>
}
)
Expand All @@ -45,22 +45,22 @@ Definition

:returns:

Returns either the original document or, if ``returnNewDocument: true``,
Returns either the original document or, if ``returnOriginal: true``,
the updated document.

Behavior
--------

:method:`~db.collection.findOneAndUpdate()` updates the first matching
document in the collection that matches the ``filter``.
:method:`~db.collection.findOneAndUpdate()` updates the first matching
document in the collection that matches the ``filter``.
The ``sort`` parameter can be used to influence which document is updated.

The ``projection`` parameter takes a document in the following form:

.. code-block:: javascript

{ field1 : < boolean >, field2 : < boolean> ... }

The ``<boolean>`` value can be any of the following:

- ``1`` or ``true`` to include the field. The method returns the
Expand Down Expand Up @@ -91,13 +91,13 @@ The ``grades`` collection contains documents similar to the following:
{ _id: 6322, name : "A. MacDyver", "assignment" : 2, "points" : 14 },
{ _id: 6234, name : "R. Stiles", "assignment" : 1, "points" : 10 }

The following operation finds the first document where ``name : R. Stiles``
The following operation finds the first document where ``name : R. Stiles``
and increments the score by ``5``:

.. code-block:: javascript

db.scores.findOneAndUpdate(
{ "name" : "R. Stiles" },
db.scores.findOneAndUpdate(
{ "name" : "R. Stiles" },
{ $inc: { "points" : 5 } }
)

Expand All @@ -106,8 +106,8 @@ The operation returns the *original* document before the update:
.. code-block:: javascript

{ _id: 6319, name: "R. Stiles", "assignment" : 2, "points" : 12 }
If ``returnNewDocument`` was true, the operation would return the

If ``returnOriginal`` was true, the operation would return the
updated document instead.

.. _findOneAndUpdate-example-sort-and-replace-document:
Expand All @@ -128,7 +128,7 @@ The ``grades`` collection contains documents similar to the following:

The following operation updates a document where ``name : "A. MacGyver"``. The
operation sorts the matching documents by ``points`` ascending to update the
matching document with the least points.
matching document with the least points.

.. code-block:: javascript

Expand All @@ -149,8 +149,8 @@ The operation returns the *original* document before the update:
Project the Returned Document
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following operation uses projection to only display the ``_id``,
``points``, and ``assignment`` fields in the returned document:
The following operation uses projection to only display the ``_id``,
``points``, and ``assignment`` fields in the returned document:

.. code-block:: javascript

Expand All @@ -159,8 +159,8 @@ The following operation uses projection to only display the ``_id``,
{ $inc : { "points" : 5 } },
{ sort : { "points" : 1 }, projection: { "assignment" : 1, "points" : 1 } }
)
The operation returns the *original* document with only the

The operation returns the *original* document with only the
fields specified in the ``projection`` document and the ``_id`` field as it was not
explicitly suppressed (``_id: 0``) in the :ref:`projection document <projections>`.

Expand Down Expand Up @@ -200,7 +200,7 @@ If the operation exceeds the time limit, it returns:
Update Document with Upsert
~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following operation uses the ``upsert`` field to insert the update
The following operation uses the ``upsert`` field to insert the update
document if nothing matches the ``filter``:

.. code-block:: javascript
Expand All @@ -209,7 +209,7 @@ document if nothing matches the ``filter``:
db.scores.findOneAndUpdate(
{ "name" : "A.B. Abracus" },
{ $set: { "name" : "A.B. Abracus", "assignment" : 5}, $inc : { "points" : 5 } },
{ sort: { "points" : 1 }, upsert:true, returnNewDocument : true }
{ sort: { "points" : 1 }, upsert:true, returnOriginal : true }
);
}
catch (e){
Expand All @@ -226,8 +226,8 @@ The operation returns the following:
"assignment" : 5,
"points" : 5
}
If ``returnNewDocument`` was false, the operation would return ``null`` as

If ``returnOriginal`` was false, the operation would return ``null`` as
there is no original document to return.

Specify Collation
Expand Down