- Reference >
- JavaScript Methods >
- cursor.batchSize()
cursor.batchSize()¶
-
cursor.batchSize()¶ The
batchSize()method 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 since themongoshell and most drivers return results as if MongoDB returned a single batch.The
batchSize()method takes the following parameter:Parameters: - size – The number of documents to return per batch. Do not use a
batch size of
1.
Note
Specifying
1or a negative number is analogous to using thelimit()method.Consider the following example of the
batchSize()method in themongoshell:This operation will set the batch size for the results of a query (i.e.
find()) to10. The effects of this operation do not affect the output in themongoshell, which always iterates over the first 20 documents.- size – The number of documents to return per batch. Do not use a
batch size of