Skip to content

Commit e56dd4e

Browse files
authored
DOCSP 23290 adding pull example with bulkWrite (#1430) (#1448)
* 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 2446454 commit e56dd4e

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
@@ -115,6 +115,70 @@ After the update operation, the document only has values less than 6:
115115

116116
.. _pull-array-of-documents:
117117

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

0 commit comments

Comments
 (0)