@@ -7,45 +7,33 @@ cursor.batchSize()
7
7
.. method:: cursor.batchSize()
8
8
9
9
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.
13
15
14
16
The :method:`batchSize() <cursor.batchSize()>` method takes the
15
17
following parameter:
16
18
17
19
:param size:
18
20
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``.
24
23
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.
28
28
29
29
Consider the following examples that use the :method:`batchSize()
30
30
<cursor.batchSize()>` method in the :program:`mongo` shell:
31
31
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:
34
36
35
37
.. code-block:: javascript
36
38
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