Docs Menu

cursor.batchSize()

On this page

  • Definition
  • Example
cursor.batchSize(size)
Important
mongosh Method

This is a mongosh method. This is not the documentation for Node.js or other programming language specific driver methods.

In most cases, mongosh methods work the same way as the legacy mongo shell methods. However, some legacy methods are unavailable in mongosh.

For the legacy mongo shell documentation, refer to the documentation for the corresponding MongoDB Server release:

For MongoDB API drivers, refer to the language specific MongoDB driver documentation.

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 mongosh 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 mongosh, which, by default, iterates over the first 20 documents.

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

On this page

Give Feedback
MongoDB logo
© 2021 MongoDB, Inc.

About

  • Careers
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.