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