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:`Cursor` has already been used. The last `limit` applied to this cursor takes precedence. A
(self, limit: int)
| 417 | return self |
| 418 | |
| 419 | def limit(self, limit: int) -> Cursor[_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:`Cursor` |
| 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) -> Cursor[_DocumentType]: |
| 442 | """Limits the number of documents returned in one batch. Each batch |