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

Method limit

pymongo/asynchronous/cursor.py:419–439  ·  view source on GitHub ↗

Limits the number of results to be returned by this cursor. Raises :exc:`TypeError` if `limit` is not an integer. Raises :exc:`~pymongo.errors.InvalidOperation` if this :class:`AsyncCursor` has already been used. The last `limit` applied to this cursor takes preceden

(self, limit: int)

Source from the content-addressed store, hash-verified

417 return self
418
419 def limit(self, limit: int) -> AsyncCursor[_DocumentType]:
420 """Limits the number of results to be returned by this cursor.
421
422 Raises :exc:`TypeError` if `limit` is not an integer. Raises
423 :exc:`~pymongo.errors.InvalidOperation` if this :class:`AsyncCursor`
424 has already been used. The last `limit` applied to this cursor
425 takes precedence. A limit of ``0`` is equivalent to no limit.
426
427 :param limit: the number of results to return
428
429 .. seealso:: The MongoDB documentation on `limit <https://dochub.mongodb.org/core/limit>`_.
430 """
431 if not isinstance(limit, int):
432 raise TypeError(f"limit must be an integer, not {type(limit)}")
433 if self._exhaust:
434 raise InvalidOperation("Can't use limit and exhaust together.")
435 self._check_okay_to_chain()
436
437 self._empty = False
438 self._limit = limit
439 return self
440
441 def batch_size(self, batch_size: int) -> AsyncCursor[_DocumentType]:
442 """Limits the number of documents returned in one batch. Each batch

Callers 2

__getitem__Method · 0.45
find_oneMethod · 0.45

Calls 2

_check_okay_to_chainMethod · 0.95
InvalidOperationClass · 0.90

Tested by

no test coverage detected