Skip to content

Commit a453809

Browse files
author
Dave
authored
Docsp 19918 update db.collection.update pt1 v5.1 (#85) (#90)
* DOCSP-19918 fix update examples pt1 * More pages * Add slice page * Review feedback
1 parent 88bf6eb commit a453809

10 files changed

+18
-24
lines changed

source/core/document.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ Update Specification Documents
330330

331331
Update specification documents use :ref:`update operators
332332
<update-operators>` to specify the data modifications to perform on
333-
specific fields during an :method:`db.collection.update()` operation.
333+
specific fields during an update operation.
334334

335335
.. code-block:: javascript
336336

source/core/retryable-writes.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ cannot be :writeconcern:`{w: 0} <\<number\>>`.
107107

108108
* - | :method:`db.collection.updateOne()`
109109
| :method:`db.collection.replaceOne()`
110-
| :method:`db.collection.update()` where ``multi`` is ``false``
111110
- Single-document update operations. [#duplicate-key-update]_
112111

113112
* - | :method:`db.collection.deleteOne()`

source/core/write-operations-atomicity.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ One approach is to create a :ref:`unique index <index-type-unique>` on a
3838
field that can only have unique values. This prevents insertions or
3939
updates from creating duplicate data. Create a unique index on multiple
4040
fields to force uniqueness on that combination of field values. For
41-
examples of use cases, see :ref:`update() and Unique Index
42-
<update-with-unique-indexes>` and :ref:`findAndModify() and Unique Index
41+
examples of use cases, see :ref:`findAndModify() and Unique Index
4342
<upsert-and-unique-index>`.
4443

4544
Another approach is to specify the expected current value of a field in

source/faq/concurrency.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ In some situations, read and write operations can yield their locks.
110110
Long running read and write operations, such as queries, updates,
111111
and deletes, yield locks under many conditions. MongoDB operations can
112112
also yield locks between individual document modifications in write
113-
operations that affect multiple documents like
114-
:method:`~db.collection.update()` with the ``multi`` parameter.
113+
operations that affect multiple documents.
115114

116115
For storage engines supporting document level :term:`concurrency
117116
control`, such as :doc:`WiredTiger </core/wiredtiger>`, yielding is not

source/includes/example-addToSet-each.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ with the :update:`$each` modifier to add multiple elements to the
1010

1111
.. code-block:: javascript
1212
13-
db.inventory.update(
13+
db.inventory.updateOne(
1414
{ _id: 2 },
1515
{ $addToSet: { tags: { $each: [ "camera", "electronics", "accessories" ] } } }
1616
)
@@ -25,3 +25,4 @@ The operation adds only ``"camera"`` and ``"accessories"`` to the
2525
item: "cable",
2626
tags: [ "electronics", "supplies", "camera", "accessories" ]
2727
}
28+

source/includes/example-push-each.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ equals ``joe``:
44

55
.. code-block:: javascript
66
7-
db.students.update(
7+
db.students.updateOne(
88
{ name: "joe" },
99
{ $push: { scores: { $each: [ 90, 92, 85 ] } } }
1010
)
11+

source/includes/example-push-with-multiple-modifiers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The following :update:`$push` operation uses:
2626

2727
.. code-block:: javascript
2828
29-
db.students.update(
29+
db.students.updateOne(
3030
{ _id: 5 },
3131
{
3232
$push: {

source/includes/extracts-collation.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,7 @@ content: |-
262262
263263
* - :dbcommand:`update`
264264
265-
- | :method:`db.collection.update()`
266-
| :method:`db.collection.updateOne()`,
265+
- | :method:`db.collection.updateOne()`,
267266
| :method:`db.collection.updateMany()`,
268267
| :method:`db.collection.replaceOne()`
269268
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
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:
73

84
- If multiple documents match the update criteria, for
95
|operation|, you can specify a ``sort`` to provide some
106
measure of control on which document to update.
117

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.
1510

1611
- By default, |operation| returns |return-object|. To
1712
obtain the updated document, use the ``new`` option.
1813

19-
The :method:`~db.collection.update()` method returns a
14+
The :method:`~db.collection.updateOne()` method returns a
2015
:method:`WriteResult` object that contains the status of the operation.
16+
2117
To return the updated document, use the :method:`~db.collection.find()`
2218
method. However, other updates may have modified the document between
2319
your update and the document retrieval. Also, if the update modified
2420
only a single document but multiple documents matched, you will need to
2521
use additional logic to identify the updated document.
2622

2723
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
2925
document. See :doc:`/core/write-operations-atomicity` for more
3026
details about interactions and order of operations of these methods.

source/reference/operator/update/slice.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ last five elements:
8686

8787
.. code-block:: javascript
8888

89-
db.students.update(
89+
db.students.updateOne(
9090
{ _id: 1 },
9191
{
9292
$push: {
@@ -120,7 +120,7 @@ first three elements.
120120

121121
.. code-block:: javascript
122122

123-
db.students.update(
123+
db.students.updateOne(
124124
{ _id: 2 },
125125
{
126126
$push: {
@@ -155,7 +155,7 @@ array ``[]`` for the :update:`$each` modifier, as in the following:
155155

156156
.. code-block:: javascript
157157

158-
db.students.update(
158+
db.students.updateOne(
159159
{ _id: 3 },
160160
{
161161
$push: {

0 commit comments

Comments
 (0)