@@ -109,6 +109,48 @@ The following example appends ``89`` to the ``scores`` array:
109
109
110
110
.. _example-push-each:
111
111
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
+
112
154
Append Multiple Values to an Array
113
155
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114
156
@@ -122,5 +164,8 @@ Use ``$push`` Operator with Multiple Modifiers
122
164
123
165
.. include:: /includes/example-push-with-multiple-modifiers.rst
124
166
125
- .. seealso:: :method:`db.collection.update()`,
167
+ .. seealso::
168
+ :method:`db.collection.update()`,
169
+ :method:`db.collection.updateMany()`,
126
170
:method:`db.collection.findAndModify()`
171
+
0 commit comments