猫鼬游标batchSize [英] mongoose cursor batchSize

查看:85
本文介绍了猫鼬游标batchSize的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在定义batchSize的情况下,如何迭代游标批处理文档? 例如,当batchSize定义为等于50时,有什么方法可以迭代50个子文档?

how to iterate the cursor batch documents in case that the batchSize is defined ? example, when the batchSize defined to be equal to 50 , is there any way to iterate that 50 sub documents ?

var myCursor = collection.find().cursor({batchSize:50});
mycursor('on',function(doc){

})

推荐答案

尝试一下:

var myCursor = collection.find({}).cursor({batchSize:50});
myCursor.eachAsync((doc) => {
   ...
});

批处理大小仅用于性能优化,不会为您提供50个对象的批处理.

Batch sizes are just for performance optimisation and will not give you a 50 object chunk.

您仍然必须分别处理每个文档.

You will still have to process each doc individually.

这篇关于猫鼬游标batchSize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆