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

Method exists

gridfs/asynchronous/grid_file.py:410–458  ·  view source on GitHub ↗

Check if a file exists in this instance of :class:`GridFS`. The file to check for can be specified by the value of its ``_id`` key, or by passing in a query document. A query document can be passed in as dictionary, or by using keyword arguments. Thus, the following

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

Source from the content-addressed store, hash-verified

408 return AsyncGridOutCursor(self._collection, *args, **kwargs)
409
410 async def exists(
411 self,
412 document_or_id: Optional[Any] = None,
413 session: Optional[AsyncClientSession] = None,
414 **kwargs: Any,
415 ) -> bool:
416 """Check if a file exists in this instance of :class:`GridFS`.
417
418 The file to check for can be specified by the value of its
419 ``_id`` key, or by passing in a query document. A query
420 document can be passed in as dictionary, or by using keyword
421 arguments. Thus, the following three calls are equivalent:
422
423 >>> fs.exists(file_id)
424 >>> fs.exists({"_id": file_id})
425 >>> fs.exists(_id=file_id)
426
427 As are the following two calls:
428
429 >>> fs.exists({"filename": "mike.txt"})
430 >>> fs.exists(filename="mike.txt")
431
432 And the following two:
433
434 >>> fs.exists({"foo": {"$gt": 12}})
435 >>> fs.exists(foo={"$gt": 12})
436
437 Returns ``True`` if a matching file exists, ``False``
438 otherwise. Calls to :meth:`exists` will not automatically
439 create appropriate indexes; application developers should be
440 sure to create indexes if needed and as appropriate.
441
442 :param document_or_id: query document, or _id of the
443 document to check for
444 :param session: a
445 :class:`~pymongo.client_session.AsyncClientSession`
446 :param kwargs: keyword arguments are used as a
447 query document, if they're present.
448
449 .. versionchanged:: 3.6
450 Added ``session`` parameter.
451 """
452 _disallow_transactions(session)
453 if kwargs:
454 f = await self._files.find_one(kwargs, ["_id"], session=session)
455 else:
456 f = await self._files.find_one(document_or_id, ["_id"], session=session)
457
458 return f is not None
459
460
461class AsyncGridFSBucket:

Callers

nothing calls this directly

Calls 2

_disallow_transactionsFunction · 0.70
find_oneMethod · 0.45

Tested by

no test coverage detected