-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathcursor.batchSize.txt
88 lines (62 loc) · 2.46 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
.. _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 maximum number of documents within each batch returned in a query result.
By default, the initial batch size is ``101`` documents and subsequent batches have a maximum
size of 16 mebibytes (MiB). This option can enforce a smaller
limit than 16 MiB, but not a larger one. If you set ``batchSize`` to a limit that results
in batches larger than 16 MiB, this option has no effect.
A batchSize of 0 means that the cursor will be established, but no documents
will be returned in the first 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 maximum number of documents to return for a batch. The
default initial batch size is ``101`` documents and subsequent
batches have a maximum size of 16 mebibytes (MiB). This option can enforce a smaller limit than
16 MiB, but not a larger one. The default applies to drivers and
Mongo Shell. For details, see :ref:`cursor-batches`.
Compatibility
-------------
This method is available in deployments hosted in the following environments:
.. include:: /includes/fact-environments-atlas-only.rst
.. include:: /includes/fact-environments-atlas-support-all.rst
.. include:: /includes/fact-environments-onprem-only.rst
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`