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

Method find

gridfs/synchronous/grid_file.py:348–406  ·  view source on GitHub ↗

Query GridFS for files. 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_out in fs.find({"filename": "lisa.txt"},

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

Source from the content-addressed store, hash-verified

346 return None
347
348 def find(self, *args: Any, **kwargs: Any) -> GridOutCursor:
349 """Query GridFS for files.
350
351 Returns a cursor that iterates across files matching
352 arbitrary queries on the files collection. Can be combined
353 with other modifiers for additional control. For example::
354
355 for grid_out in fs.find({"filename": "lisa.txt"},
356 no_cursor_timeout=True):
357 data = grid_out.read()
358
359 would iterate through all versions of "lisa.txt" stored in GridFS.
360 Note that setting no_cursor_timeout to True may be important to
361 prevent the cursor from timing out during long multi-file processing
362 work.
363
364 As another example, the call::
365
366 most_recent_three = fs.find().sort("uploadDate", -1).limit(3)
367
368 would return a cursor to the three most recently uploaded files
369 in GridFS.
370
371 Follows a similar interface to
372 :meth:`~pymongo.collection.Collection.find`
373 in :class:`~pymongo.collection.Collection`.
374
375 If a :class:`~pymongo.client_session.ClientSession` is passed to
376 :meth:`find`, all returned :class:`~gridfs.grid_file.GridOut` instances
377 are associated with that session.
378
379 :param filter: A query document that selects which files
380 to include in the result set. Can be an empty document to include
381 all files.
382 :param skip: the number of files to omit (from
383 the start of the result set) when returning the results
384 :param limit: the maximum number of results to
385 return
386 :param no_cursor_timeout: if False (the default), any
387 returned cursor is closed by the server after 10 minutes of
388 inactivity. If set to True, the returned cursor will never
389 time out on the server. Care should be taken to ensure that
390 cursors with no_cursor_timeout turned on are properly closed.
391 :param sort: a list of (key, direction) pairs
392 specifying the sort order for this query. See
393 :meth:`~pymongo.cursor.Cursor.sort` for details.
394
395 Raises :class:`TypeError` if any of the arguments are of
396 improper type. Returns an instance of
397 :class:`~gridfs.grid_file.GridOutCursor`
398 corresponding to this query.
399
400 .. versionchanged:: 3.0
401 Removed the read_preference, tag_sets, and
402 secondary_acceptable_latency_ms options.
403 .. versionadded:: 2.7
404 .. seealso:: The MongoDB documentation on `find <https://dochub.mongodb.org/core/find>`_.
405 """

Callers 6

find_oneMethod · 0.95
get_versionMethod · 0.45
delete_by_nameMethod · 0.45
_read_size_or_lineMethod · 0.45
_create_cursorMethod · 0.45

Calls 1

GridOutCursorClass · 0.85

Tested by

no test coverage detected