Skip to content

Update db.collection.findAndModify.txt #1583

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
34 changes: 17 additions & 17 deletions source/reference/method/db.collection.findAndModify.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ Definition

.. code-block:: none

db.collection.findAndModify( {
query: <document>,
sort: <document>,
remove: <boolean>,
update: <document>,
new: <boolean>,
fields: <document>,
upsert: <boolean>
} );
db.collection.findAndModify({
query: <document>,
sort: <document>,
remove: <boolean>,
update: <document>,
new: <boolean>,
fields: <document>,
upsert: <boolean>
});

The :method:`db.collection.findAndModify()` method takes a document
parameter with the following subdocument fields:
Expand Down Expand Up @@ -89,12 +89,12 @@ and multiple clients issue the following command:

.. code-block:: javascript

db.people.findAndModify( {
db.people.findAndModify({
query: { name: "Andy" },
sort: { rating: 1 },
update: { $inc: { score: 1 } },
upsert: true
} )
})

Then, if these clients' :method:`~db.collection.findAndModify()`
methods finish the ``query`` phase before any command starts the
Expand Down Expand Up @@ -137,11 +137,11 @@ people collection where the document matches the query criteria:

.. code-block:: javascript

db.people.findAndModify( {
db.people.findAndModify({
query: { name: "Tom", state: "active", rating: { $gt: 10 } },
sort: { rating: 1 },
update: { $inc: { score: 1 } }
} )
})

This method performs the following actions:

Expand Down Expand Up @@ -190,12 +190,12 @@ condition:

.. code-block:: javascript

db.people.findAndModify( {
db.people.findAndModify({
query: { name: "Gus", state: "active", rating: 100 },
sort: { rating: 1 },
update: { $inc: { score: 1 } },
upsert: true
} )
})

If the method does **not** find a matching document, the method
performs an upsert. Because the method included the ``sort``
Expand All @@ -222,13 +222,13 @@ document matching the ``query`` is not found:

.. code-block:: none

db.people.findAndModify( {
db.people.findAndModify({
query: { name: "Pascal", state: "active", rating: 25 },
sort: { rating: 1 },
update: { $inc: { score: 1 } },
upsert: true,
new: true
} )
})

The method returns the newly inserted document:

Expand Down