Delete a single document matching the filter. >>> await db.test.count_documents({'x': 1}) 3 >>> result = await db.test.delete_one({'x': 1}) >>> result.deleted_count 1 >>> await db.test.count_documents({'x': 1}) 2 :param
(
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,
)
| 1592 | ) |
| 1593 | |
| 1594 | async def delete_one( |
| 1595 | self, |
| 1596 | filter: Mapping[str, Any], |
| 1597 | collation: Optional[_CollationIn] = None, |
| 1598 | hint: Optional[_IndexKeyHint] = None, |
| 1599 | session: Optional[AsyncClientSession] = None, |
| 1600 | let: Optional[Mapping[str, Any]] = None, |
| 1601 | comment: Optional[Any] = None, |
| 1602 | ) -> DeleteResult: |
| 1603 | """Delete a single document matching the filter. |
| 1604 | |
| 1605 | >>> await db.test.count_documents({'x': 1}) |
| 1606 | 3 |
| 1607 | >>> result = await db.test.delete_one({'x': 1}) |
| 1608 | >>> result.deleted_count |
| 1609 | 1 |
| 1610 | >>> await db.test.count_documents({'x': 1}) |
| 1611 | 2 |
| 1612 | |
| 1613 | :param filter: A query that matches the document to delete. |
| 1614 | :param collation: An instance of |
| 1615 | :class:`~pymongo.collation.Collation`. |
| 1616 | :param hint: An index to use to support the query |
| 1617 | predicate specified either by its string name, or in the same |
| 1618 | format as passed to |
| 1619 | :meth:`~pymongo.asynchronous.collection.AsyncCollection.create_index` (e.g. |
| 1620 | ``[('field', ASCENDING)]``). This option is only supported on |
| 1621 | MongoDB 4.4 and above. |
| 1622 | :param session: a |
| 1623 | :class:`~pymongo.asynchronous.client_session.AsyncClientSession`. |
| 1624 | :param let: Map of parameter names and values. Values must be |
| 1625 | constant or closed expressions that do not reference document |
| 1626 | fields. Parameters can then be accessed as variables in an |
| 1627 | aggregate expression context (e.g. "$$var"). |
| 1628 | :param comment: A user-provided comment to attach to this |
| 1629 | command. |
| 1630 | |
| 1631 | :return: - An instance of :class:`~pymongo.results.DeleteResult`. |
| 1632 | |
| 1633 | .. versionchanged:: 4.1 |
| 1634 | Added ``let`` parameter. |
| 1635 | Added ``comment`` parameter. |
| 1636 | .. versionchanged:: 3.11 |
| 1637 | Added ``hint`` parameter. |
| 1638 | .. versionchanged:: 3.6 |
| 1639 | Added ``session`` parameter. |
| 1640 | .. versionchanged:: 3.4 |
| 1641 | Added the `collation` option. |
| 1642 | .. versionadded:: 3.0 |
| 1643 | """ |
| 1644 | write_concern = self._write_concern_for(session) |
| 1645 | return DeleteResult( |
| 1646 | await self._delete_retryable( |
| 1647 | filter, |
| 1648 | False, |
| 1649 | write_concern=write_concern, |
| 1650 | collation=collation, |
| 1651 | hint=hint, |
no test coverage detected