cursor.batchSize()

On this page本页内容

Definition定义

cursor.batchSize(size)

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. 本页记录了mongo shell方法,未提及MongoDB Node.js驱动程序(或任何其他驱动程序)方法。For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.有关相应的MongoDB驱动程序API,请参阅特定的MongoDB驱动程序文档。

Specifies the number of documents to return in each batch of the response from the MongoDB instance. 指定MongoDB实例每批响应中要返回的文档数。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.在大多数情况下,修改批大小不会影响用户或应用程序,因为mongo shell和大多数驱动程序返回的结果就像MongoDB返回单个批一样。

The batchSize() method takes the following parameter:batchSize()方法采用以下参数:

Parameter参数Type类型Description描述
size integer The number of documents to return per batch. 每批要返回的文档数。Do not use a batch size of 1.不要使用1的批量大小。

Note

Specifying 1 or a negative number is analogous to using the limit() method.指定1或负数类似于使用limit()方法。

Example示例

The following example sets the batch size for the results of a query (i.e. find()) to 10. 以下示例将查询结果(即find())的批量大小设置为10The batchSize() method does not change the output in the mongo shell, which, by default, iterates over the first 20 documents.batchSize()方法不会更改mongo shell中的输出,默认情况下,mongo shell会迭代前20个文档。

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