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

Method limit

pymongo/synchronous/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:`Cursor` has already been used. The last `limit` applied to this cursor takes precedence. A

(self, limit: int)

Source from the content-addressed store, hash-verified

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

Callers 15

get_versionMethod · 0.45
get_versionMethod · 0.45
test_gridfs_findMethod · 0.45
test_exhaustMethod · 0.45
test_limitMethod · 0.45
test_batch_sizeMethod · 0.45
test_rewindMethod · 0.45
test_cloneMethod · 0.45

Calls 2

_check_okay_to_chainMethod · 0.95
InvalidOperationClass · 0.90

Tested by 15

test_gridfs_findMethod · 0.36
test_exhaustMethod · 0.36
test_limitMethod · 0.36
test_batch_sizeMethod · 0.36
test_rewindMethod · 0.36
test_cloneMethod · 0.36
test_to_list_tailableMethod · 0.36
test_gridfs_findMethod · 0.36
test_exhaustMethod · 0.36
test_limitMethod · 0.36