MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / DeleteMany

Class DeleteMany

pymongo/operations.py:257–315  ·  view source on GitHub ↗

Represents a delete_many operation.

Source from the content-addressed store, hash-verified

255
256
257class DeleteMany(_DeleteOp):
258 """Represents a delete_many operation."""
259
260 __slots__ = ()
261
262 def __init__(
263 self,
264 filter: Mapping[str, Any],
265 collation: Optional[_CollationIn] = None,
266 hint: Optional[_IndexKeyHint] = None,
267 namespace: Optional[str] = None,
268 ) -> None:
269 """Create a DeleteMany instance.
270
271 For use with :meth:`~pymongo.asynchronous.collection.AsyncCollection.bulk_write`, :meth:`~pymongo.collection.Collection.bulk_write`,
272 :meth:`~pymongo.asynchronous.mongo_client.AsyncMongoClient.bulk_write` and :meth:`~pymongo.mongo_client.MongoClient.bulk_write`.
273
274 :param filter: A query that matches the documents to delete.
275 :param collation: An instance of
276 :class:`~pymongo.collation.Collation`.
277 :param hint: An index to use to support the query
278 predicate specified either by its string name, or in the same
279 format as passed to
280 :meth:`~pymongo.asynchronous.collection.AsyncCollection.create_index` or :meth:`~pymongo.collection.Collection.create_index` (e.g.
281 ``[('field', ASCENDING)]``). This option is only supported on
282 MongoDB 4.4 and above.
283 :param namespace: (optional) The namespace in which to delete documents.
284
285 .. versionchanged:: 4.9
286 Added the `namespace` option to support `MongoClient.bulk_write`.
287 .. versionchanged:: 3.11
288 Added the ``hint`` option.
289 .. versionchanged:: 3.5
290 Added the `collation` option.
291 """
292 super().__init__(filter, collation, hint, namespace)
293
294 def _add_to_bulk(self, bulkobj: _AgnosticBulk) -> None:
295 """Add this operation to the _AsyncBulk/_Bulk instance `bulkobj`."""
296 bulkobj.add_delete(
297 self._filter,
298 0,
299 collation=validate_collation_or_none(self._collation),
300 hint=self._hint,
301 )
302
303 def _add_to_client_bulk(self, bulkobj: _AgnosticClientBulk) -> None:
304 """Add this operation to the _AsyncClientBulk/_ClientBulk instance `bulkobj`."""
305 if not self._namespace:
306 raise InvalidOperation(
307 "MongoClient.bulk_write requires a namespace to be provided for each write operation"
308 )
309 bulkobj.add_delete(
310 self._namespace,
311 self._filter,
312 multi=True,
313 collation=validate_collation_or_none(self._collation),
314 hint=self._hint,

Callers 12

test_bulk_writeMethod · 0.90
test_DeleteManyEqualsMethod · 0.90
callbackMethod · 0.90
test_bulk_writeMethod · 0.90
test_removeMethod · 0.85
test_no_removeMethod · 0.85
test_removeMethod · 0.85
test_no_removeMethod · 0.85

Calls

no outgoing calls

Tested by 12

test_bulk_writeMethod · 0.72
test_DeleteManyEqualsMethod · 0.72
callbackMethod · 0.72
test_bulk_writeMethod · 0.72
test_removeMethod · 0.68
test_no_removeMethod · 0.68
test_removeMethod · 0.68
test_no_removeMethod · 0.68