Skip to content

Commit f94b4cb

Browse files
committed
DOCS-579 batchSize link to limit for negative size and 1
1 parent 7871ea3 commit f94b4cb

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

source/reference/method/cursor.batchSize.txt

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,33 @@ cursor.batchSize()
77
.. method:: cursor.batchSize()
88

99
The :method:`batchSize() <cursor.batchSize()>` method specifies the
10-
number of documents the cursor will return in each batch. In most
11-
cases, the effect of configuring the batch size will not affect the
12-
user or application.
10+
number of documents to return in each batch; MongoDB server returns
11+
query results in batches. In most cases, the effect of configuring
12+
the batch size will not affect the user or the application since the
13+
:program:`mongo` shell and most driver present the results
14+
seamlessly as though returned in a single batch.
1315

1416
The :method:`batchSize() <cursor.batchSize()>` method takes the
1517
following parameter:
1618

1719
:param size:
1820

19-
The number of documents to return per batch. This value
20-
also affects whether to close the cursor after the first
21-
batch. Refer to the specific driver ``batchSize``
22-
documentation for the cursor behavior as determined by the
23-
``size``.
21+
The number of documents to return per batch. Do **not** use a
22+
batch size of ``1``.
2423

25-
The :program:`mongo` shell will iterate over 20 documents
26-
regardless of the configured batch size, unless you specify a
27-
negative batch size.
24+
.. note::
25+
26+
Specifying ``1`` or a negative number is analogous to using the
27+
:method:`limit() <cursor.limit()>` method.
2828

2929
Consider the following examples that use the :method:`batchSize()
3030
<cursor.batchSize()>` method in the :program:`mongo` shell:
3131

32-
- Set the number of documents returned by the :method:`find()
33-
<db.collection.find()>` method to ``10`` per each batch:
32+
- Set the batch size so that the results of the :method:`find()` are
33+
returned in batches of ``10``. The effects of the batch size is
34+
not visible to the user as the :program:`mongo` shell iterate over
35+
the first 20 documents:
3436

3537
.. code-block:: javascript
3638

37-
var curs = db.animals.find().batchSize(10)
38-
39-
The cursor remains open so that you can iterate through the cursor
40-
``curs`` to access all documents in the ``animals`` collection.
41-
42-
- Set the number of documents returned by the :method:`find()
43-
<db.collection.find()>` method to ``10`` per each batch and close
44-
after the first batch:
45-
46-
.. code-block:: javascript
47-
48-
var curs = db.animals.find().batchSize(-10)
49-
50-
In the :program:`mongo` shell, the cursor closes after the first
51-
batch so that you can iterate the cursor only ``10`` times.
39+
db.animals.find().batchSize(10)

0 commit comments

Comments
 (0)