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

Method find

pymongo/asynchronous/collection.py:1759–1954  ·  view source on GitHub ↗

Query the database. The `filter` argument is a query document that all results must match. For example: >>> db.test.find({"hello": "world"}) only matches documents that have a key "hello" with value "world". Matches can have other keys *in addition* to

(self, *args: Any, **kwargs: Any)

Source from the content-addressed store, hash-verified

1757 return None
1758
1759 def find(self, *args: Any, **kwargs: Any) -> AsyncCursor[_DocumentType]:
1760 """Query the database.
1761
1762 The `filter` argument is a query document that all results
1763 must match. For example:
1764
1765 >>> db.test.find({"hello": "world"})
1766
1767 only matches documents that have a key "hello" with value
1768 "world". Matches can have other keys *in addition* to
1769 "hello". The `projection` argument is used to specify a subset
1770 of fields that should be included in the result documents. By
1771 limiting results to a certain subset of fields you can cut
1772 down on network traffic and decoding time.
1773
1774 Raises :class:`TypeError` if any of the arguments are of
1775 improper type. Returns an instance of
1776 :class:`~pymongo.asynchronous.cursor.AsyncCursor` corresponding to this query.
1777
1778 Cursors are closed automatically when they are exhausted (the last batch of data is retrieved from the database).
1779 If a cursor is not exhausted, it will be closed automatically upon garbage collection, which leaves resources open but unused for a potentially long period of time.
1780 To avoid this, best practice is to call :meth:`AsyncCursor.close` when the cursor is no longer needed,
1781 or use the cursor in a with statement::
1782
1783 async with collection.find() as cursor:
1784 async for doc in cursor:
1785 print(doc)
1786
1787 The :meth:`find` method obeys the :attr:`read_preference` of
1788 this :class:`AsyncCollection`.
1789
1790 :param filter: A query document that selects which documents
1791 to include in the result set. Can be an empty document to include
1792 all documents.
1793 :param projection: a list of field names that should be
1794 returned in the result set or a dict specifying the fields
1795 to include or exclude. If `projection` is a list "_id" will
1796 always be returned. Use a dict to exclude fields from
1797 the result (e.g. projection={'_id': False}).
1798 :param session: a
1799 :class:`~pymongo.asynchronous.client_session.AsyncClientSession`.
1800 :param skip: the number of documents to omit (from
1801 the start of the result set) when returning the results
1802 :param limit: the maximum number of results to
1803 return. A limit of 0 (the default) is equivalent to setting no
1804 limit.
1805 :param no_cursor_timeout: if False (the default), any
1806 returned cursor is closed by the server after 10 minutes of
1807 inactivity. If set to True, the returned cursor will never
1808 time out on the server. Care should be taken to ensure that
1809 cursors with no_cursor_timeout turned on are properly closed.
1810 :param cursor_type: the type of cursor to return. The valid
1811 options are defined by :class:`~pymongo.cursor.CursorType`:
1812
1813 - :attr:`~pymongo.cursor.CursorType.NON_TAILABLE` - the result of
1814 this find call will return a standard cursor over the result set.
1815 - :attr:`~pymongo.cursor.CursorType.TAILABLE` - the result of this
1816 find call will be a tailable cursor - tailable cursors are only

Callers 4

find_oneMethod · 0.95
validate_collectionMethod · 0.45
fetch_keysMethod · 0.45
get_keysMethod · 0.45

Calls 1

AsyncCursorClass · 0.90

Tested by

no test coverage detected