Skip to content

Commit c1cf803

Browse files
authored
DOCSP 22373 - adding updateMany() example to push (#1455) (#1471)
* DOCSP-22373 adding new push example * DOCSP-22373 adding new push example * DOCSP-22373 adding new push example * DOCSP-22373 adding new push example * DOCSP-22373 adding new push example * DOCSP-22373 minor edits * DOCSP-22373 minor word change
1 parent 8491a48 commit c1cf803

File tree

1 file changed

+46
-1
lines changed
  • source/reference/operator/update

1 file changed

+46
-1
lines changed

source/reference/operator/update/push.txt

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,48 @@ The following example appends ``89`` to the ``scores`` array:
109109

110110
.. _example-push-each:
111111

112+
Append a Value to Arrays in Multiple Documents
113+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114+
115+
Add the following documents to the ``students`` collection:
116+
117+
.. code-block:: javascript
118+
119+
db.students.insertMany( [
120+
{ _id: 2, scores: [ 45, 78, 38, 80, 89 ] } ,
121+
{ _id: 3, scores: [ 46, 78, 38, 80, 89 ] } ,
122+
{ _id: 4, scores: [ 47, 78, 38, 80, 89 ] }
123+
] )
124+
125+
The following :update:`$push` operation appends ``95`` to the
126+
``scores`` array in each document:
127+
128+
.. code-block:: javascript
129+
130+
db.students.updateMany(
131+
{ },
132+
{ $push: { scores: 95 } }
133+
)
134+
135+
To confirm that each ``scores`` array includes ``95``, run the following
136+
operation:
137+
138+
.. code-block:: javascript
139+
140+
db.students.find()
141+
142+
The operation returns the following results:
143+
144+
.. code-block:: javascript
145+
:copyable: false
146+
147+
[
148+
{ _id: 1, scores: [ 44, 78, 38, 80, 89, 95 ] },
149+
{ _id: 2, scores: [ 45, 78, 38, 80, 89, 95 ] },
150+
{ _id: 3, scores: [ 46, 78, 38, 80, 89, 95 ] },
151+
{ _id: 4, scores: [ 47, 78, 38, 80, 89, 95 ] }
152+
]
153+
112154
Append Multiple Values to an Array
113155
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114156

@@ -122,5 +164,8 @@ Use ``$push`` Operator with Multiple Modifiers
122164

123165
.. include:: /includes/example-push-with-multiple-modifiers.rst
124166

125-
.. seealso:: :method:`db.collection.update()`,
167+
.. seealso::
168+
:method:`db.collection.update()`,
169+
:method:`db.collection.updateMany()`,
126170
:method:`db.collection.findAndModify()`
171+

0 commit comments

Comments
 (0)