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