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

Method delete_many

pymongo/synchronous/collection.py:1658–1721  ·  view source on GitHub ↗

Delete one or more documents matching the filter. >>> db.test.count_documents({'x': 1}) 3 >>> result = db.test.delete_many({'x': 1}) >>> result.deleted_count 3 >>> db.test.count_documents({'x': 1}) 0 :param filter: A que

(
        self,
        filter: Mapping[str, Any],
        collation: Optional[_CollationIn] = None,
        hint: Optional[_IndexKeyHint] = None,
        session: Optional[ClientSession] = None,
        let: Optional[Mapping[str, Any]] = None,
        comment: Optional[Any] = None,
    )

Source from the content-addressed store, hash-verified

1656 )
1657
1658 def delete_many(
1659 self,
1660 filter: Mapping[str, Any],
1661 collation: Optional[_CollationIn] = None,
1662 hint: Optional[_IndexKeyHint] = None,
1663 session: Optional[ClientSession] = None,
1664 let: Optional[Mapping[str, Any]] = None,
1665 comment: Optional[Any] = None,
1666 ) -> DeleteResult:
1667 """Delete one or more documents matching the filter.
1668
1669 >>> db.test.count_documents({'x': 1})
1670 3
1671 >>> result = db.test.delete_many({'x': 1})
1672 >>> result.deleted_count
1673 3
1674 >>> db.test.count_documents({'x': 1})
1675 0
1676
1677 :param filter: A query that matches the documents to delete.
1678 :param collation: An instance of
1679 :class:`~pymongo.collation.Collation`.
1680 :param hint: An index to use to support the query
1681 predicate specified either by its string name, or in the same
1682 format as passed to
1683 :meth:`~pymongo.collection.Collection.create_index` (e.g.
1684 ``[('field', ASCENDING)]``). This option is only supported on
1685 MongoDB 4.4 and above.
1686 :param session: a
1687 :class:`~pymongo.client_session.ClientSession`.
1688 :param let: Map of parameter names and values. Values must be
1689 constant or closed expressions that do not reference document
1690 fields. Parameters can then be accessed as variables in an
1691 aggregate expression context (e.g. "$$var").
1692 :param comment: A user-provided comment to attach to this
1693 command.
1694
1695 :return: - An instance of :class:`~pymongo.results.DeleteResult`.
1696
1697 .. versionchanged:: 4.1
1698 Added ``let`` parameter.
1699 Added ``comment`` parameter.
1700 .. versionchanged:: 3.11
1701 Added ``hint`` parameter.
1702 .. versionchanged:: 3.6
1703 Added ``session`` parameter.
1704 .. versionchanged:: 3.4
1705 Added the `collation` option.
1706 .. versionadded:: 3.0
1707 """
1708 write_concern = self._write_concern_for(session)
1709 return DeleteResult(
1710 self._delete_retryable(
1711 filter,
1712 True,
1713 write_concern=write_concern,
1714 collation=collation,
1715 hint=hint,

Callers 15

deleteMethod · 0.45
deleteMethod · 0.45
delete_by_nameMethod · 0.45
abortMethod · 0.45
deleteMethod · 0.45
deleteMethod · 0.45
delete_by_nameMethod · 0.45
abortMethod · 0.45
test_batch_splittingMethod · 0.45
_test_no_gc_deadlockMethod · 0.45

Calls 3

_delete_retryableMethod · 0.95
DeleteResultClass · 0.90
_write_concern_forMethod · 0.80

Tested by 15

test_batch_splittingMethod · 0.36
_test_no_gc_deadlockMethod · 0.36
test_session_gcMethod · 0.36
test_deleteMethod · 0.36
test_deleteMethod · 0.36
test_non_bulk_writesMethod · 0.36