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

Method batch_size

pymongo/synchronous/cursor.py:441–466  ·  view source on GitHub ↗

Limits the number of documents returned in one batch. Each batch requires a round trip to the server. It can be adjusted to optimize performance and limit data transfer. .. note:: batch_size can not override MongoDB's internal limits on the amount of data it will

(self, batch_size: int)

Source from the content-addressed store, hash-verified

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
443 requires a round trip to the server. It can be adjusted to optimize
444 performance and limit data transfer.
445
446 .. note:: batch_size can not override MongoDB's internal limits on the
447 amount of data it will return to the client in a single batch (i.e
448 if you set batch size to 1,000,000,000, MongoDB will currently only
449 return 4-16MB of results per batch).
450
451 Raises :exc:`TypeError` if `batch_size` is not an integer.
452 Raises :exc:`ValueError` if `batch_size` is less than ``0``.
453 Raises :exc:`~pymongo.errors.InvalidOperation` if this
454 :class:`Cursor` has already been used. The last `batch_size`
455 applied to this cursor takes precedence.
456
457 :param batch_size: The size of each batch of results requested.
458 """
459 if not isinstance(batch_size, int):
460 raise TypeError(f"batch_size must be an integer, not {type(batch_size)}")
461 if batch_size < 0:
462 raise ValueError("batch_size must be >= 0")
463 self._check_okay_to_chain()
464
465 self._batch_size = batch_size
466 return self
467
468 def skip(self, skip: int) -> Cursor[_DocumentType]:
469 """Skips the first `skip` results of this cursor.

Calls 1

_check_okay_to_chainMethod · 0.95

Tested by 15

test_kill_cursorsMethod · 0.36
insert_and_findMethod · 0.36
insert_and_aggregateMethod · 0.36
test_batch_sizeMethod · 0.36
test_get_moreMethod · 0.36
test_aliveMethod · 0.36
test_kill_cursorsMethod · 0.36