Skip to content

Commit 227ad9e

Browse files
authored
DOCSP 23290 adding pull example with bulkWrite (#1430)
* DOCSP-23290 adding pull bulkWrite example * DOCSP-23290 adding pull bulkWrite example * DOCSP-23290 adding pull bulkWrite example * DOCSP-23290 adding pull bulkWrite example * DOCSP-23290 adding pull bulkWrite example * DOCSP-23290 adding pull bulkWrite example * DOCSP-23290 pull example edits * DOCSP-23290 pull example edits * DOCSP-23290 pull example edits * DOCSP-23290 pull example edits * DOCSP-23290 pull example edits * DOCSP-23290 phrase change
1 parent c21bbc7 commit 227ad9e

File tree

1 file changed

+64
-0
lines changed
  • source/reference/operator/update

1 file changed

+64
-0
lines changed

source/reference/operator/update/pull.txt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,70 @@ After the update operation, the document only has values less than 6:
118118

119119
.. _pull-array-of-documents:
120120

121+
Remove All Items That Match a Specified ``$pull`` Condition With :method:`~db.collection.bulkWrite()`
122+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123+
124+
The following :method:`db.collection.bulkWrite()` operation:
125+
126+
- Creates the ``profilesBulkWrite`` collection.
127+
128+
- Removes all items from the ``votes`` array
129+
that are greater than or equal to ( :query:`$gte` ) ``6``.
130+
131+
- Removes all items from the ``votes`` array
132+
that are less than or equal to ( :query:`$lte` ) ``3``.
133+
134+
135+
.. code-block:: javascript
136+
137+
try {
138+
db.profilesBulkWrite.bulkWrite( [
139+
{
140+
insertOne: {
141+
"document": { _id: 1, votes: [ 3, 5, 6, 7, 7, 8 ] }
142+
}
143+
},
144+
{
145+
updateOne: {
146+
"filter": { _id: 1 },
147+
"update": { $pull: { votes: { $gte: 6 } } }
148+
}
149+
},
150+
{
151+
updateOne: {
152+
"filter": {_id: 1},
153+
"update": { $pull: { votes: { $lte: 3 } } }
154+
}
155+
}
156+
] );
157+
} catch (e) {
158+
print(e);
159+
}
160+
161+
.. note:: `bulkWrite()`
162+
163+
The :method:`db.collection.bulkWrite()` method executes multiple
164+
write operations listed in an array. In this example, the
165+
:method:`db.collection.bulkWrite()` performs multiple operations
166+
on the ``profiles`` collection.
167+
168+
After the :method:`db.collection.bulkWrite()` operation,
169+
you can confirm the document only has values less than
170+
6 and greater than 3 using the following
171+
operation:
172+
173+
.. code-block:: javascript
174+
175+
db.profilesBulkWrite.find()
176+
177+
The operation returns the following:
178+
179+
.. code-block:: javascript
180+
:copyable: false
181+
182+
[ { _id: 1, votes: [ 5 ] } ]
183+
184+
121185
Remove Items from an Array of Documents
122186
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123187

0 commit comments

Comments
 (0)