Navigation

cursor.batchSize()

cursor.batchSize(size)
Important
mongo Shell Method

This page documents the mongo shell method, and does not refer to the MongoDB Node.js driver (or any other driver) method. For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.

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 the mongo shell and most drivers return results as if MongoDB returned a single batch.

The batchSize() method takes the following parameter:

Parameter
Type
Description
size
integer
The number of documents to return per batch. Do not use a batch size of 1.
Note

Specifying 1 or a negative number is analogous to using the limit() method.

The following example sets the batch size for the results of a query (i.e. find()) to 10. The batchSize() method does not change the output in the mongo shell, which, by default, iterates over the first 20 documents.

db.inventory.find().batchSize(10)
Give Feedback

On this page

  • Definition
  • Example