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

Class AsyncGridOutCursor

gridfs/asynchronous/grid_file.py:1938–2008  ·  view source on GitHub ↗

A cursor / iterator for returning GridOut objects as the result of an arbitrary query against the GridFS files collection.

Source from the content-addressed store, hash-verified

1936
1937
1938class AsyncGridOutCursor(AsyncCursor): # type: ignore[type-arg]
1939 """A cursor / iterator for returning GridOut objects as the result
1940 of an arbitrary query against the GridFS files collection.
1941 """
1942
1943 def __init__(
1944 self,
1945 collection: AsyncCollection[Any],
1946 filter: Optional[Mapping[str, Any]] = None,
1947 skip: int = 0,
1948 limit: int = 0,
1949 no_cursor_timeout: bool = False,
1950 sort: Optional[Any] = None,
1951 batch_size: int = 0,
1952 session: Optional[AsyncClientSession] = None,
1953 ) -> None:
1954 """Create a new cursor, similar to the normal
1955 :class:`~pymongo.cursor.Cursor`.
1956
1957 Should not be called directly by application developers - see
1958 the :class:`~gridfs.GridFS` method :meth:`~gridfs.GridFS.find` instead.
1959
1960 .. versionadded 2.7
1961
1962 .. seealso:: The MongoDB documentation on `cursors <https://dochub.mongodb.org/core/cursors>`_.
1963 """
1964 _disallow_transactions(session)
1965 collection = _clear_entity_type_registry(collection)
1966
1967 # Hold on to the base "fs" collection to create GridOut objects later.
1968 self._root_collection = collection
1969
1970 super().__init__(
1971 collection.files,
1972 filter,
1973 skip=skip,
1974 limit=limit,
1975 no_cursor_timeout=no_cursor_timeout,
1976 sort=sort,
1977 batch_size=batch_size,
1978 session=session,
1979 )
1980
1981 async def next(self) -> AsyncGridOut:
1982 """Get next GridOut object from cursor."""
1983 _disallow_transactions(self.session)
1984 next_file = await super().next()
1985 return AsyncGridOut(self._root_collection, file_document=next_file, session=self.session)
1986
1987 async def to_list(self, length: Optional[int] = None) -> list[AsyncGridOut]:
1988 """Convert the cursor to a list."""
1989 if length is None:
1990 return [x async for x in self] # noqa: C416,RUF100
1991 if length < 1:
1992 raise ValueError("to_list() length must be greater than 0")
1993 ret = []
1994 for _ in range(length):
1995 ret.append(await self.next())

Callers 4

findMethod · 0.85
findMethod · 0.85
_clone_baseMethod · 0.85

Calls

no outgoing calls

Tested by 1