@@ -25,15 +25,15 @@ Definition
25
25
26
26
.. code-block:: none
27
27
28
- db.collection.findAndModify( {
29
- query: <document>,
30
- sort: <document>,
31
- remove: <boolean>,
32
- update: <document>,
33
- new: <boolean>,
34
- fields: <document>,
35
- upsert: <boolean>
36
- } );
28
+ db.collection.findAndModify({
29
+ query: <document>,
30
+ sort: <document>,
31
+ remove: <boolean>,
32
+ update: <document>,
33
+ new: <boolean>,
34
+ fields: <document>,
35
+ upsert: <boolean>
36
+ } );
37
37
38
38
The :method:`db.collection.findAndModify()` method takes a document
39
39
parameter with the following subdocument fields:
@@ -89,12 +89,12 @@ and multiple clients issue the following command:
89
89
90
90
.. code-block:: javascript
91
91
92
- db.people.findAndModify( {
92
+ db.people.findAndModify({
93
93
query: { name: "Andy" },
94
94
sort: { rating: 1 },
95
95
update: { $inc: { score: 1 } },
96
96
upsert: true
97
- } )
97
+ })
98
98
99
99
Then, if these clients' :method:`~db.collection.findAndModify()`
100
100
methods finish the ``query`` phase before any command starts the
@@ -137,11 +137,11 @@ people collection where the document matches the query criteria:
137
137
138
138
.. code-block:: javascript
139
139
140
- db.people.findAndModify( {
140
+ db.people.findAndModify({
141
141
query: { name: "Tom", state: "active", rating: { $gt: 10 } },
142
142
sort: { rating: 1 },
143
143
update: { $inc: { score: 1 } }
144
- } )
144
+ })
145
145
146
146
This method performs the following actions:
147
147
@@ -190,12 +190,12 @@ condition:
190
190
191
191
.. code-block:: javascript
192
192
193
- db.people.findAndModify( {
193
+ db.people.findAndModify({
194
194
query: { name: "Gus", state: "active", rating: 100 },
195
195
sort: { rating: 1 },
196
196
update: { $inc: { score: 1 } },
197
197
upsert: true
198
- } )
198
+ } )
199
199
200
200
If the method does **not** find a matching document, the method
201
201
performs an upsert. Because the method included the ``sort``
@@ -222,13 +222,13 @@ document matching the ``query`` is not found:
222
222
223
223
.. code-block:: none
224
224
225
- db.people.findAndModify( {
225
+ db.people.findAndModify({
226
226
query: { name: "Pascal", state: "active", rating: 25 },
227
227
sort: { rating: 1 },
228
228
update: { $inc: { score: 1 } },
229
229
upsert: true,
230
230
new: true
231
- } )
231
+ })
232
232
233
233
The method returns the newly inserted document:
234
234
0 commit comments