MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / find

Method find

gridfs/synchronous/grid_file.py:860–905  ·  view source on GitHub ↗

Find and return the files collection documents that match ``filter`` Returns a cursor that iterates across files matching arbitrary queries on the files collection. Can be combined with other modifiers for additional control. For example:: for grid_data i

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

Source from the content-addressed store, hash-verified

858 raise NoFile(f"no file could be deleted because none matched filename {filename!r}")
859
860 def find(self, *args: Any, **kwargs: Any) -> GridOutCursor:
861 """Find and return the files collection documents that match ``filter``
862
863 Returns a cursor that iterates across files matching
864 arbitrary queries on the files collection. Can be combined
865 with other modifiers for additional control.
866
867 For example::
868
869 for grid_data in fs.find({"filename": "lisa.txt"},
870 no_cursor_timeout=True):
871 data = grid_data.read()
872
873 would iterate through all versions of "lisa.txt" stored in GridFS.
874 Note that setting no_cursor_timeout to True may be important to
875 prevent the cursor from timing out during long multi-file processing
876 work.
877
878 As another example, the call::
879
880 most_recent_three = fs.find().sort("uploadDate", -1).limit(3)
881
882 would return a cursor to the three most recently uploaded files
883 in GridFS.
884
885 Follows a similar interface to
886 :meth:`~pymongo.collection.Collection.find`
887 in :class:`~pymongo.collection.Collection`.
888
889 If a :class:`~pymongo.client_session.ClientSession` is passed to
890 :meth:`find`, all returned :class:`~gridfs.grid_file.GridOut` instances
891 are associated with that session.
892
893 :param filter: Search query.
894 :param batch_size: The number of documents to return per
895 batch.
896 :param limit: The maximum number of documents to return.
897 :param no_cursor_timeout: The server normally times out idle
898 cursors after an inactivity period (10 minutes) to prevent excess
899 memory use. Set this option to True prevent that.
900 :param skip: The number of documents to skip before
901 returning.
902 :param sort: The order by which to sort results. Defaults to
903 None.
904 """
905 return GridOutCursor(self._collection, *args, **kwargs)
906
907 def open_download_stream_by_name(
908 self, filename: str, revision: int = -1, session: Optional[ClientSession] = None

Callers 1

Calls 1

GridOutCursorClass · 0.85

Tested by 1