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

Method find_one

pymongo/asynchronous/collection.py:1724–1757  ·  view source on GitHub ↗

Get a single document from the database. All arguments to :meth:`find` are also valid arguments for :meth:`find_one`, although any `limit` argument will be ignored. Returns a single document, or ``None`` if no matching document is found. The :meth:`find_one`

(
        self, filter: Optional[Any] = None, *args: Any, **kwargs: Any
    )

Source from the content-addressed store, hash-verified

1722 )
1723
1724 async def find_one(
1725 self, filter: Optional[Any] = None, *args: Any, **kwargs: Any
1726 ) -> Optional[_DocumentType]:
1727 """Get a single document from the database.
1728
1729 All arguments to :meth:`find` are also valid arguments for
1730 :meth:`find_one`, although any `limit` argument will be
1731 ignored. Returns a single document, or ``None`` if no matching
1732 document is found.
1733
1734 The :meth:`find_one` method obeys the :attr:`read_preference` of
1735 this :class:`AsyncCollection`.
1736
1737 :param filter: a dictionary specifying
1738 the query to be performed OR any other type to be used as
1739 the value for a query for ``"_id"``.
1740
1741 :param args: any additional positional arguments
1742 are the same as the arguments to :meth:`find`.
1743
1744 :param kwargs: any additional keyword arguments
1745 are the same as the arguments to :meth:`find`.
1746
1747 :: code-block: python
1748
1749 >>> await collection.find_one(max_time_ms=100)
1750
1751 """
1752 if filter is not None and not isinstance(filter, abc.Mapping):
1753 filter = {"_id": filter}
1754 cursor = self.find(filter, *args, **kwargs)
1755 async for result in cursor.limit(-1):
1756 return result
1757 return None
1758
1759 def find(self, *args: Any, **kwargs: Any) -> AsyncCursor[_DocumentType]:
1760 """Query the database.

Callers 3

dereferenceMethod · 0.45
get_keyMethod · 0.45
get_key_by_alt_nameMethod · 0.45

Calls 2

findMethod · 0.95
limitMethod · 0.45

Tested by

no test coverage detected