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

Method find_one

gridfs/asynchronous/grid_file.py:310–348  ·  view source on GitHub ↗

Get a single file from gridfs. All arguments to :meth:`find` are also valid arguments for :meth:`find_one`, although any `limit` argument will be ignored. Returns a single :class:`~gridfs.grid_file.GridOut`, or ``None`` if no matching file is found. For example:

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

Source from the content-addressed store, hash-verified

308 ]
309
310 async def find_one(
311 self,
312 filter: Optional[Any] = None,
313 session: Optional[AsyncClientSession] = None,
314 *args: Any,
315 **kwargs: Any,
316 ) -> Optional[AsyncGridOut]:
317 """Get a single file from gridfs.
318
319 All arguments to :meth:`find` are also valid arguments for
320 :meth:`find_one`, although any `limit` argument will be
321 ignored. Returns a single :class:`~gridfs.grid_file.GridOut`,
322 or ``None`` if no matching file is found. For example:
323
324 .. code-block: python
325
326 file = fs.find_one({"filename": "lisa.txt"})
327
328 :param filter: a dictionary specifying
329 the query to be performing OR any other type to be used as
330 the value for a query for ``"_id"`` in the file collection.
331 :param args: any additional positional arguments are
332 the same as the arguments to :meth:`find`.
333 :param session: a
334 :class:`~pymongo.client_session.AsyncClientSession`
335 :param kwargs: any additional keyword arguments
336 are the same as the arguments to :meth:`find`.
337
338 .. versionchanged:: 3.6
339 Added ``session`` parameter.
340 """
341 if filter is not None and not isinstance(filter, abc.Mapping):
342 filter = {"_id": filter}
343
344 _disallow_transactions(session)
345 async for f in self.find(filter, *args, session=session, **kwargs):
346 return f
347
348 return None
349
350 def find(self, *args: Any, **kwargs: Any) -> AsyncGridOutCursor:
351 """Query GridFS for files.

Callers 3

existsMethod · 0.45
_create_indexMethod · 0.45
openMethod · 0.45

Calls 2

findMethod · 0.95
_disallow_transactionsFunction · 0.70

Tested by

no test coverage detected