Skip to content

DOCSP-47795 change batchsize descriptions #6292

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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
13 changes: 10 additions & 3 deletions source/reference/command/find.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,16 @@ The command accepts the following fields:

* - ``batchSize``
- non-negative integer
- Optional. The number of documents to return in the first batch.
Defaults to 101. A batchSize of 0 means that the cursor will be
established, but no documents will be returned in the first batch.
- Optional. The maximum number of documents within each batch returned
in a query result. By default, the ``find`` command has an initial
batch size of ``101`` documents and a maximum size of 16 mebibytes (MiB)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 16MiB (Eng should confirm if MB or MiB, I can't recall) applies to all batches. In other words, by default (assuming more than 1 batch):

  • The initial batch is the lesser of 101 docs or 16MiB worth of docs
  • Subsequent batches are 16MiB worth of docs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!

for each subsequent batch. 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 and
the ``find`` command uses the default batch size.
`
A ``batchSize`` of ``0`` means that the cursor is established,
but no documents are returned in the first batch.

Unlike the previous wire protocol version, a batchSize of 1 for
the :dbcommand:`find` command does not close the cursor.
Expand Down
14 changes: 9 additions & 5 deletions source/reference/command/getMore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,15 @@ The command accepts the following fields:

* - ``batchSize``
- positive integer
- Optional. The number of documents to return in the batch.

If ``batchSize`` is not set, ``getMore`` returns up to 16
mebibytes of data. If ``batchSize`` is set, ``getMore`` returns
the smaller of 16 mebibytes of data or ``batchSize`` documents.
- Optional. Specifies the maximum number of documents within each
batch returned in a query result.

If ``batchSize`` is not set, ``getMore`` returns up to ``101`` documents
in the first batch and up to 16 mebibytes (MiB) of data in all

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a user issues a query (either a find or an aggregate) it first is received by the server as an instance of that particular command (eg find). If the full result set is not returned by the server in that initial response (eg the "initial batch") then the server opens up a cursor and tells the client about that as well when responding with the initial results. If the client wants to read more results from that cursor then that is when it issues a getMore command.

All this to say that the text here about "101 results in the initial batch of a getmore" is not correct/relevant

subsequent batches. If ``batchSize`` is set, ``getMore`` returns
the smaller of 16 MiB of data or ``batchSize`` documents. If you set
``batchSize`` to a limit that results in batches larger than 16 MiB, this
option has no effect and ``getMore`` uses the default batch size.

* - ``maxTimeMS``
- non-negative integer
Expand Down
23 changes: 14 additions & 9 deletions source/reference/method/cursor.batchSize.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ Definition

.. include:: /includes/fact-mongosh-shell-method.rst

Specifies the
number of documents to return in each batch of the response from the
MongoDB instance. In most cases, modifying the batch size will
not affect the user or the application, as :binary:`~bin.mongosh` and
most :driver:`drivers </>` return results as if MongoDB returned a
single batch.
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 and :method:`~cursor.batchSize()` uses
the default batch size.

A ``batchSize`` of ``0`` means that the cursor is established, but no documents
are returned in the first batch.

.. note::

Expand All @@ -51,9 +55,10 @@ Definition

* - ``size``
- integer
- The initial number of documents to return for a batch. The
default initial batch size is 101 documents. Subsequent
batches are 16 mebibytes. The default applies to drivers and
- 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
Expand Down
10 changes: 7 additions & 3 deletions source/reference/method/db.collection.watch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,17 @@ Definition
* - ``batchSize``

- int
- Optional. Specifies the maximum number of change events to return in each
batch of the response from the MongoDB cluster.
- Optional. The maximum number of documents within each batch returned
in a change stream. By default, :method:`~db.collection.watch()` has
an initial batch size of ``101`` documents and a maximum size
of 16 mebibytes (MiB) for each subsequent batch. 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 and :method:`~db.collection.watch()` uses
the default batch size.

Has the same functionality as :method:`cursor.batchSize()`.



* - ``maxAwaitTimeMS``

- int
Expand Down
9 changes: 6 additions & 3 deletions source/reference/operator/aggregation/queryStats.txt
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,12 @@ Each document in the output array contains the following fields:
* - ``key.batchSize``
- String
- Normalized
- The :ref:`batch size <cursor-batchSize>` for the key. Batch size
specifies the number of documents to return in each batch of the
response from the MongoDB instance.
- The :ref:`batch size <cursor-batchSize>` for the key. Batch size
specifies the maximum number of documents returned within each batch
from the MongoDB instance. By default, the initial batch size is
``101`` documents and subsequent batches have a maximum size of 16
mebibytes (MiB). ``batchSize`` can enforce a smaller limit than 16 MiB,
but not a larger one.

* - ``key.comment``
- String
Expand Down