简体   繁体   English

Mongoose / MongoDB batchSize(30)仍返回所有结果

[英]Mongoose/MongoDB batchSize(30) still returning all results

The following query returns all my users. 以下查询返回我的所有用户。 I was hoping it would be batched. 我希望它将被批量处理。

statics.findAllUsers = function findAllUsers(callback) {
  this.find({}, callback).batchSize(30);
};

batchSize() instructs the driver to retrieve a certain number of items per time. batchSize()指示驱动程序每次检索一定数量的项目。 It'll still get everything from the DB, only a batch at a time. 它仍然可以从数据库中获取所有信息,一次只能一批。

To make it clearer: If you use batchSize(30) then it'll ask for 30 items then, when you need the 31st, it'll query the next 30 and so forth. 更清楚地说:如果使用batchSize(30)它将要求30个项目,然后,当需要第31个项目时,它将查询下一个30个项目,依此类推。

If you need only that number of items, then use limit() (and offset() to set which is the first item) 如果只需要该数量的项目,则使用limit() (和offset()设置第一个项目)

Docs: http://docs.mongodb.org/manual/reference/method/cursor.batchSize/ 文件: http//docs.mongodb.org/manual/reference/method/cursor.batchSize/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM