Skip to content

Batch size 1 #320

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

Merged
merged 3 commits into from
Oct 16, 2012
Merged
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
53 changes: 53 additions & 0 deletions source/reference/method/cursor.batchSize.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
==================
cursor.batchSize()
==================

.. default-domain:: mongodb

.. method:: cursor.batchSize()

The :method:`batchSize() <cursor.batchSize()>` method specifies the
number of documents the cursor returns per batch. Specifying the
batchSize is a low-level optimization whose effects are not visible
to the user.

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

:param size:

The number of documents to return per batch. The ``size``
also affects whether to close the cursor after the first
batch. Refer to the specific driver ``batchSize``
documentation for the cursor behavior as determined by the
``size``.

.. note::

The actual number of documents in the batch may be smaller as
determined by the limit or the 4 megabyte size limit of the
server reply.

Consider the following examples of the :method:`batchSize()
<cursor.batchSize()>` method in the :program:`mongo` shell:

- Set the number of documents returned by the :method:`find()
<db.collection.find()>` method to ``10`` per each batch:

.. code-block:: javascript

var curs = db.animals.find().batchSize(10)

The cursor remains open so that you can iterate through the cursor
``curs`` to access all documents in the ``animals`` collection.

- Set the number of documents returned by the :method:`find()
<db.collection.find()>` method to ``10`` per each batch and close
after the first batch:

.. code-block:: javascript

var curs = db.animals.find().batchSize(-10)

In the :program:`mongo` shell, the cursor closes after the first
batch so that you can iterate the cursor only ``10`` times.