|
1 | 1 | When updating a document, |operation| and the |
2 | | -:method:`~db.collection.update()` method operate differently: |
3 | | - |
4 | | -- By default, both operations modify a single document. However, the |
5 | | - :method:`~db.collection.update()` method with its ``multi`` option |
6 | | - can modify more than one document. |
| 2 | +:method:`~db.collection.updateOne()` method operate differently: |
7 | 3 |
|
8 | 4 | - If multiple documents match the update criteria, for |
9 | 5 | |operation|, you can specify a ``sort`` to provide some |
10 | 6 | measure of control on which document to update. |
11 | 7 |
|
12 | | - With the default behavior of the :method:`~db.collection.update()` |
13 | | - method, you cannot specify which single document to update when |
14 | | - multiple documents match. |
| 8 | + :method:`~db.collection.updateOne()` updates the first document that |
| 9 | + matches. |
15 | 10 |
|
16 | 11 | - By default, |operation| returns |return-object|. To |
17 | 12 | obtain the updated document, use the ``new`` option. |
18 | 13 |
|
19 | | - The :method:`~db.collection.update()` method returns a |
| 14 | + The :method:`~db.collection.updateOne()` method returns a |
20 | 15 | :method:`WriteResult` object that contains the status of the operation. |
| 16 | + |
21 | 17 | To return the updated document, use the :method:`~db.collection.find()` |
22 | 18 | method. However, other updates may have modified the document between |
23 | 19 | your update and the document retrieval. Also, if the update modified |
24 | 20 | only a single document but multiple documents matched, you will need to |
25 | 21 | use additional logic to identify the updated document. |
26 | 22 |
|
27 | 23 | When modifying a *single* document, both |operation| and the |
28 | | -:method:`~db.collection.update()` method *atomically* update the |
| 24 | +:method:`~db.collection.updateOne()` method *atomically* update the |
29 | 25 | document. See :doc:`/core/write-operations-atomicity` for more |
30 | 26 | details about interactions and order of operations of these methods. |
0 commit comments