cursor.batchSize()
Definition
mongo
Shell Method
This page documents the mongo
shell method, and doesnot refer to the MongoDB Node.js driver (or any other driver)method. For corresponding MongoDB driver API, refer to your specificMongoDB driver documentation instead.
Specifies thenumber of documents to return in each batch of the response from theMongoDB instance. In most cases, modifying the batch size willnot affect the user or the application, as themongo
shell and most drivers return results as if MongoDB returned asingle batch.
The batchSize()
method takes thefollowing parameter:
ParameterTypeDescriptionsize
integerThe number of documents to return per batch. Do not use a batchsize of 1
.
Note
Specifying 1
or a negative number is analogous to using thelimit()
method.
Example
The following example sets the batch size for the results of a query(i.e. find()
) to 10
. ThebatchSize()
method does not change theoutput in the mongo
shell, which, by default, iterates over thefirst 20 documents.
- db.inventory.find().batchSize(10)