Skip to content

Commit 50210db

Browse files
author
Dave
authored
DOCSP-20016 updates for update pt5 v5.2 (#126) (#130)
* DOCSP-20016 updates for update pt5 * DOCSP-20016 additional files * Add sort * Staging updates * Staging Updates * Review feedback
1 parent ca0d7fa commit 50210db

File tree

6 files changed

+157
-98
lines changed

6 files changed

+157
-98
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
A collection ``students`` has the following document:
1+
Add the following document to the ``students`` collection:
22

33
.. code-block:: javascript
44
5-
{
6-
"_id" : 5,
7-
"quizzes" : [
8-
{ "wk": 1, "score" : 10 },
9-
{ "wk": 2, "score" : 8 },
10-
{ "wk": 3, "score" : 5 },
11-
{ "wk": 4, "score" : 6 }
12-
]
13-
}
5+
db.students.insertOne(
6+
{
7+
"_id" : 5,
8+
"quizzes" : [
9+
{ "wk": 1, "score" : 10 },
10+
{ "wk": 2, "score" : 8 },
11+
{ "wk": 3, "score" : 5 },
12+
{ "wk": 4, "score" : 6 }
13+
]
14+
}
15+
)
1416
1517
The following :update:`$push` operation uses:
1618

source/reference/operator/update/inc.txt

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,29 @@ generate an error.
4444
Example
4545
-------
4646

47-
Consider a collection ``products`` with the following document:
47+
Create the ``products`` collection:
4848

4949
.. code-block:: javascript
5050

51-
{
52-
_id: 1,
53-
sku: "abc123",
54-
quantity: 10,
55-
metrics: {
56-
orders: 2,
57-
ratings: 3.5
58-
}
59-
}
51+
db.products.insertOne(
52+
{
53+
_id: 1,
54+
sku: "abc123",
55+
quantity: 10,
56+
metrics: { orders: 2, ratings: 3.5 }
57+
}
58+
)
59+
60+
The following :method:`~db.collection.updateOne()` operation uses the
61+
:update:`$inc` operator to:
62+
63+
- increase the ``"metrics.orders"`` field by 1
64+
- increase the ``quantity`` field by -2 (which decreases ``quantity``)
6065

61-
The following :method:`~db.collection.update()` operation uses the
62-
:update:`$inc` operator to decrease the ``quantity`` field by ``2``
63-
(i.e. increase by ``-2``) and increase the ``"metrics.orders"`` field
64-
by ``1``:
6566

6667
.. code-block:: javascript
6768

68-
db.products.update(
69+
db.products.updateOne(
6970
{ sku: "abc123" },
7071
{ $inc: { quantity: -2, "metrics.orders": 1 } }
7172
)
@@ -75,16 +76,14 @@ The updated document would resemble:
7576
.. code-block:: javascript
7677

7778
{
78-
"_id" : 1,
79-
"sku" : "abc123",
80-
"quantity" : 8,
81-
"metrics" : {
82-
"orders" : 3,
83-
"ratings" : 3.5
84-
}
79+
_id: 1,
80+
sku: 'abc123',
81+
quantity: 8,
82+
metrics: { orders: 3, ratings: 3.5 }
8583
}
8684

8785
.. seealso::
8886

89-
- :method:`db.collection.update()`
87+
- :method:`db.collection.updateMany()`
9088
- :method:`db.collection.findAndModify()`
89+

source/reference/operator/update/max.txt

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,17 @@ Examples
4545
Use ``$max`` to Compare Numbers
4646
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4747

48-
Consider the following document in the collection ``scores``:
48+
Create the ``scores`` collection:
4949

5050
.. code-block:: javascript
5151

5252
db.scores.insertOne( { _id: 1, highScore: 800, lowScore: 200 } )
5353

54-
The ``highScore`` for the document currently has the value
55-
``800``. The following operation uses :update:`$max` to compare the
56-
``800`` and the specified value ``950`` and updates the value of
57-
``highScore`` to ``950`` since ``950`` is greater than ``800``:
54+
The ``highScore`` for the document currently has the value 800. The
55+
following operation:
56+
57+
- Compares the ``highscore``, 800, to the specified value, 950
58+
- Updates ``highScore`` to 950 since 950 is greater than 800
5859

5960
.. code-block:: javascript
6061

@@ -66,12 +67,12 @@ The ``scores`` collection now contains the following modified document:
6667

6768
{ _id: 1, highScore: 950, lowScore: 200 }
6869

69-
The next operation has no effect since the current value of the
70-
field ``highScore``, i.e. ``950``, is greater than ``870``:
70+
The next operation has no effect since the value of ``highScore``, 950,
71+
is greater than 870:
7172

7273
.. code-block:: javascript
7374

74-
db.scores.update( { _id: 1 }, { $max: { highScore: 870 } } )
75+
db.scores.updateOne( { _id: 1 }, { $max: { highScore: 870 } } )
7576

7677
The document remains unchanged in the ``scores`` collection:
7778

@@ -82,31 +83,33 @@ The document remains unchanged in the ``scores`` collection:
8283
Use ``$max`` to Compare Dates
8384
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8485

85-
Consider the following document in the collection ``tags``:
86+
Create the ``tags`` collection:
8687

8788
.. code-block:: javascript
8889

89-
{
90-
_id: 1,
91-
desc: "crafts",
92-
dateEntered: ISODate("2013-10-01T05:00:00Z"),
93-
dateExpired: ISODate("2013-10-01T16:38:16.163Z")
94-
}
90+
db.tags.insertOne(
91+
{
92+
_id: 1,
93+
desc: "crafts",
94+
dateEntered: ISODate("2013-10-01T05:00:00Z"),
95+
dateExpired: ISODate("2013-10-01T16:38:16.163Z")
96+
}
97+
)
9598

9699
The following operation compares the current value of the
97-
``dateExpired`` field, i.e.
98-
``ISODate("2013-10-01T16:38:16.163Z")``, with the specified date
99-
``new Date("2013-09-30")`` to determine whether to update the
100-
field:
100+
``dateExpired`` field, ``ISODate("2013-10-01T16:38:16.163Z")``, with
101+
the specified date ``new Date("2013-09-30")`` to determine whether to
102+
update the field:
101103

102104
.. code-block:: javascript
103105

104-
db.tags.update(
106+
db.tags.updateOne(
105107
{ _id: 1 },
106108
{ $max: { dateExpired: new Date("2013-09-30") } }
107109
)
108110

109-
The operation does *not* update the ``dateExpired`` field:
111+
``new Date("2013-09-30")`` is not the newest date, so the operation
112+
does *not* update the ``dateExpired`` field:
110113

111114
.. code-block:: javascript
112115
:emphasize-lines: 5
@@ -120,5 +123,6 @@ The operation does *not* update the ``dateExpired`` field:
120123

121124
.. seealso::
122125

123-
- :method:`db.collection.update()`
126+
- :method:`db.collection.updateMany()`
124127
- :method:`db.collection.findAndModify()`
128+

source/reference/operator/update/pullAll.txt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,28 @@ the specified ``<value>`` exactly, including order.
4242
Examples
4343
--------
4444

45-
Given the following document in the ``survey`` collection:
45+
Create the ``survey`` collection:
4646

4747
.. code-block:: javascript
4848

49-
{ _id: 1, scores: [ 0, 2, 5, 5, 1, 0 ] }
49+
db.survey.insertOne( { _id: 1, scores: [ 0, 2, 5, 5, 1, 0 ] } )
5050

51-
The following operation removes all instances of the value ``0`` and
52-
``5`` from the ``scores`` array:
51+
The following operation removes all instances of the values "0" and "5"
52+
from the ``scores`` array:
5353

5454
.. code-block:: javascript
5555

56-
db.survey.update( { _id: 1 }, { $pullAll: { scores: [ 0, 5 ] } } )
56+
db.survey.updateOne( { _id: 1 }, { $pullAll: { scores: [ 0, 5 ] } } )
5757

58-
After the operation, the updated document has all instances of ``0``
59-
and ``5`` removed from the ``scores`` field:
58+
After the update, the ``scores`` field no longer has any instances of
59+
"0" or "5".
6060

6161
.. code-block:: javascript
6262

6363
{ "_id" : 1, "scores" : [ 2, 1 ] }
6464

6565
.. seealso::
6666

67-
- :method:`db.collection.update()`
67+
- :method:`db.collection.updateMany()`
6868
- :method:`db.collection.findAndModify()`
69+

source/reference/operator/update/set.txt

Lines changed: 70 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,21 @@ or create each field.
5454
Examples
5555
--------
5656

57-
Consider a collection ``products`` with the following document:
57+
Create the ``products`` collection:
5858

5959
.. code-block:: javascript
6060

61-
{
62-
_id: 100,
63-
sku: "abc123",
64-
quantity: 250,
65-
instock: true,
66-
reorder: false,
67-
details: { model: "14Q2", make: "xyz" },
68-
tags: [ "apparel", "clothing" ],
69-
ratings: [ { by: "ijk", rating: 4 } ]
70-
}
61+
db.products.insertOne(
62+
{
63+
_id: 100,
64+
quantity: 250,
65+
instock: true,
66+
reorder: false,
67+
details: { model: "14QQ", make: "Clothes Corp" },
68+
tags: [ "apparel", "clothing" ],
69+
ratings: [ { by: "Customer007", rating: 4 } ]
70+
}
71+
)
7172

7273
Set Top-Level Fields
7374
~~~~~~~~~~~~~~~~~~~~
@@ -79,20 +80,35 @@ field.
7980

8081
.. code-block:: javascript
8182

82-
db.products.update(
83+
db.products.updateOne(
8384
{ _id: 100 },
8485
{ $set:
8586
{
8687
quantity: 500,
87-
details: { model: "14Q3", make: "xyz" },
88+
details: { model: "2600", make: "Fashionaires" },
8889
tags: [ "coats", "outerwear", "clothing" ]
8990
}
9091
}
9192
)
9293

93-
The operation replaces the value of: ``quantity`` to ``500``; the
94-
``details`` field to a new embedded document, and the ``tags`` field to
95-
a new array.
94+
The operation updates the:
95+
96+
- value of ``quantity`` to ``500``
97+
- ``details`` field with new embedded document
98+
- ``tags`` field with new array
99+
100+
.. code-block:: javascript
101+
:copyable: false
102+
103+
{
104+
_id: 100,
105+
quantity: 500,
106+
instock: true,
107+
reorder: false,
108+
details: { model: '2600', make: 'Fashionaires' },
109+
tags: [ 'coats', 'outerwear', 'clothing' ],
110+
ratings: [ { by: 'Customer007', rating: 4 } ]
111+
}
96112

97113
Set Fields in Embedded Documents
98114
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -105,11 +121,27 @@ document:
105121

106122
.. code-block:: javascript
107123

108-
db.products.update(
124+
db.products.updateOne(
109125
{ _id: 100 },
110-
{ $set: { "details.make": "zzz" } }
126+
{ $set: { "details.make": "Kustom Kidz" } }
111127
)
112128

129+
After updating, the document has the following values:
130+
131+
.. code-block:: javascript
132+
:copyable: false
133+
134+
{
135+
_id: 100,
136+
quantity: 500,
137+
instock: true,
138+
reorder: false,
139+
details: { model: '2600', make: 'Kustom Kidz' },
140+
tags: [ 'coats', 'outerwear', 'clothing' ],
141+
ratings: [ { by: 'Customer007', rating: 4 } ]
142+
}
143+
144+
113145
Set Elements in Arrays
114146
~~~~~~~~~~~~~~~~~~~~~~
115147

@@ -122,7 +154,7 @@ element (array index of ``0``) of the ``ratings`` array.
122154

123155
.. code-block:: javascript
124156

125-
db.products.update(
157+
db.products.updateOne(
126158
{ _id: 100 },
127159
{ $set:
128160
{
@@ -132,10 +164,28 @@ element (array index of ``0``) of the ``ratings`` array.
132164
}
133165
)
134166

167+
168+
After updating, the document has the following values:
169+
170+
.. code-block:: javascript
171+
:copyable: false
172+
173+
{
174+
_id: 100,
175+
quantity: 500,
176+
instock: true,
177+
reorder: false,
178+
details: { model: '2600', make: 'Kustom Kidz' },
179+
tags: [ 'coats', 'rain gear', 'clothing' ],
180+
ratings: [ { by: 'Customer007', rating: 2 } ]
181+
}
182+
183+
135184
For additional update operators for arrays, see
136185
:doc:`/reference/operator/update-array`.
137186

138187
.. seealso::
139188

140-
- :method:`db.collection.update()`
189+
- :method:`db.collection.updateMany()`
141190
- :method:`db.collection.findAndModify()`
191+

0 commit comments

Comments
 (0)