mongodb / v3.6 / reference / reference-method-cursor.batchSize.html

cursor.batchSize()

在本页面

Definition

  • cursor. batchSize(* size *)
    • 指定在 MongoDB 实例的每批响应中要返回的文档数。在大多数情况下,修改批处理大小不会影响用户或应用程序,因为mongo shell 和大多数drivers返回结果,就像 MongoDB 返回单个批处理一样。

batchSize()方法采用以下参数:

Parameter Type Description
size integer 每批退回的文档数。 不要 使用1的批处理大小。

Note

指定1或负数类似于使用limit()方法。

Example

以下示例将查询结果(即find())的批处理大小设置为10batchSize()方法不会更改mongo shell 中的输出,该 shell 默认情况下会迭代前 20 个文档。

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