-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
cursor.batchSize.txt
74 lines (54 loc) · 1.85 KB
/
cursor.batchSize.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
.. _cursor-batchSize:
==================
cursor.batchSize()
==================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. method:: cursor.batchSize(size)
.. include:: /includes/fact-mongosh-shell-method.rst
Specifies the
number of documents to return in each batch of the response from the
MongoDB instance. In most cases, modifying the batch size will
not affect the user or the application, as :binary:`~bin.mongosh` and
most :driver:`drivers </>` return results as if MongoDB returned a
single batch.
.. note::
If the batch size is too large, the cursor allocates more
resources than it requires, which can negatively impact
query performance. If the batch size is too small, the
cursor requires more network round trips to retrieve the
query results, which can negatively impact query
performance.
Adjust ``batchSize`` to a value appropriate to your
database, load, and application needs.
The :method:`~cursor.batchSize()` method takes the
following field:
.. list-table::
:header-rows: 1
:widths: 20 20 80
* - Field
- Type
- Description
* - ``size``
- integer
- The initial number of documents to return for a batch. The
default initial batch size is 101 documents. Subsequent
batches are 16 megabytes. The default applies to drivers and
Mongo Shell. For details, see :ref:`cursor-batches`.
Example
-------
The following example sets ``batchSize`` for the results of a query
(specifically, :method:`~db.collection.find()`) to ``10``:
.. code-block:: javascript
db.inventory.find().batchSize(10)
Learn More
----------
- :ref:`cursor-batches`
- :method:`cursor.next()`
- :dbcommand:`getMore`