Skip to content

Commit ba764f4

Browse files
author
Dave
authored
DOCSP-20016 BACKPORT (#131)
* DOCSP-20016 updates for update pt5 * DOCSP-20016 additional files * Add sort * Staging updates * Staging Updates * Review feedback
1 parent 8f8da7d commit ba764f4

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
{ _id: 1, highScore: 800, lowScore: 200 }
5353

54-
The ``highScore`` for the document currently has the value
55-
``800``. The following operation uses :operator:`$max` to compare
56-
the ``800`` and the specified value ``950`` and updates the value
57-
of ``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
@@ -52,20 +52,21 @@ or create each field.
5252
Examples
5353
--------
5454

55-
Consider a collection ``products`` with the following document:
55+
Create the ``products`` collection:
5656

5757
.. code-block:: javascript
5858

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

7071
Set Top-Level Fields
7172
~~~~~~~~~~~~~~~~~~~~
@@ -77,20 +78,35 @@ field.
7778

7879
.. code-block:: javascript
7980

80-
db.products.update(
81+
db.products.updateOne(
8182
{ _id: 100 },
8283
{ $set:
8384
{
8485
quantity: 500,
85-
details: { model: "14Q3", make: "xyz" },
86+
details: { model: "2600", make: "Fashionaires" },
8687
tags: [ "coats", "outerwear", "clothing" ]
8788
}
8889
}
8990
)
9091

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

95111
Set Fields in Embedded Documents
96112
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -103,11 +119,27 @@ document:
103119

104120
.. code-block:: javascript
105121

106-
db.products.update(
122+
db.products.updateOne(
107123
{ _id: 100 },
108-
{ $set: { "details.make": "zzz" } }
124+
{ $set: { "details.make": "Kustom Kidz" } }
109125
)
110126

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

@@ -120,7 +152,7 @@ element (array index of ``0``) of the ``ratings`` array.
120152

121153
.. code-block:: javascript
122154

123-
db.products.update(
155+
db.products.updateOne(
124156
{ _id: 100 },
125157
{ $set:
126158
{
@@ -130,10 +162,28 @@ element (array index of ``0``) of the ``ratings`` array.
130162
}
131163
)
132164

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

136185
.. seealso::
137186

138-
- :method:`db.collection.update()`
187+
- :method:`db.collection.updateMany()`
139188
- :method:`db.collection.findAndModify()`
189+

0 commit comments

Comments
 (0)