Skip to content

DOCS-7018: batch size update #2757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions source/tutorial/iterate-a-cursor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,33 @@ situation, see the information on :ref:`snapshot mode
Cursor Batches
~~~~~~~~~~~~~~

The MongoDB server returns the query results in batches. Batch size
will not exceed the :ref:`maximum BSON document size
<limit-bson-document-size>`. For most queries, the *first* batch
returns 101 documents or just enough documents to exceed 1 megabyte.
Subsequent batch size is 4 megabytes. To override the default size of
The MongoDB server returns the query results in batches. The amount of
data in the batch will not exceed the :ref:`maximum BSON document size
<limit-bson-document-size>`. To override the default size of
the batch, see :method:`~cursor.batchSize()` and
:method:`~cursor.limit()`.

.. versionadded:: 3.4

Operations of type :method:`~db.collection.find()`,
:method:`~db.collection.aggregate()`,
:dbcommand:`listIndexes`, and
:dbcommand:`listCollections` return a maximum of 16 megabytes
per batch. :method:`~cursor.batchSize()` can enforce a smaller
limit, but not a larger one.

``find()`` and ``aggregate()`` operations have an initial batch size
of 101 documents by default. Subsequent :dbcommand:`getMore`
operations issued against the resulting cursor have no default batch
size, so they are limited only by the 16 megabyte message size.

For queries that include a sort operation *without* an index, the
server must load all the documents in memory to perform the sort
before returning any results.

As you iterate through the cursor and reach the end of the returned
batch, if there are more results, :method:`cursor.next()` will perform
a :data:`getmore operation <currentOp.op>` to retrieve the next batch.
a :data:`getMore operation <currentOp.op>` to retrieve the next batch.
To see how many documents remain in the batch as you iterate the
cursor, you can use the :method:`~cursor.objsLeftInBatch()` method, as
in the following example:
Expand Down