如何通过mongoose非阻塞获取大数据?

我如何通过mongoose获得大量的收集,我得到的每一个文件返回,而不是整个集合的巨大数组?

目前我只使用以下查询:

var query = templateData.find({}); query.exec(function (err, docs) { // docs as array }); 

这样,查询function就像阻塞IO而不是非阻塞。 有没有办法让这个更无阻塞?

那么,因为发布这个问题之后,我又看了一下mongoose的文档,我又得到了stream()函数,它完美地填充了非阻塞操作。

怪我,但我认为可以在mongoose文档中提到更多的攻击: http : //mongoosejs.com/docs/api.html#query_Query-stream

 var query = templateData.find({}).stream(); query.on('data', function (doc) { // do something with the mongoose document }).on('error', function (err) { // handle the error }).on('close', function () { // the stream is closed }); 

看起来新标准可能是使用游标 。