@@ -7,44 +7,42 @@ 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 returns per batch. Specifying the
11
- batchSize is a low-level optimization whose effects are not visible
12
- to the user .
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 .
13
13
14
14
The :method:`batchSize() <cursor.batchSize()>` method takes the
15
15
following parameter:
16
16
17
- :param size:
18
-
19
- The number of documents to return per batch. The ``size``
17
+ :param size:
18
+
19
+ The number of documents to return per batch. This value
20
20
also affects whether to close the cursor after the first
21
21
batch. Refer to the specific driver ``batchSize``
22
22
documentation for the cursor behavior as determined by the
23
23
``size``.
24
24
25
- .. note::
26
-
27
- The actual number of documents in the batch may be smaller as
28
- determined by the limit or the 4 megabyte size limit of the
29
- server reply.
30
-
31
- Consider the following examples of the :method:`batchSize()
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.
28
+
29
+ Consider the following examples that use the :method:`batchSize()
32
30
<cursor.batchSize()>` method in the :program:`mongo` shell:
33
-
31
+
34
32
- Set the number of documents returned by the :method:`find()
35
33
<db.collection.find()>` method to ``10`` per each batch:
36
-
34
+
37
35
.. code-block:: javascript
38
36
39
37
var curs = db.animals.find().batchSize(10)
40
-
38
+
41
39
The cursor remains open so that you can iterate through the cursor
42
40
``curs`` to access all documents in the ``animals`` collection.
43
41
44
42
- Set the number of documents returned by the :method:`find()
45
43
<db.collection.find()>` method to ``10`` per each batch and close
46
44
after the first batch:
47
-
45
+
48
46
.. code-block:: javascript
49
47
50
48
var curs = db.animals.find().batchSize(-10)
0 commit comments