On this page本页内容
cursor.batchSize(size)
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.有关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 在大多数情况下,修改批大小不会影响用户或应用程序,因为mongosh
and most drivers return results as if MongoDB returned a single batch.mongosh
和大多数驱动程序都会返回结果,就像MongoDB返回单个批一样。
The batchSize()
method takes the following parameter:batchSize()
方法采用以下参数:
size | integer | 1 .1 。 |
The following example sets the batch size for the results of a query (i.e. 以下示例将查询结果的批大小(即find()
) to 10
. find()
)设置为10
。The batchSize()
method does not change the output in mongosh
, which, by default, iterates over the first 20 documents.batchSize()
方法不会更改mongosh
中的输出,默认情况下,mongosh
会迭代前20个文档。
db.inventory.find().batchSize(10)