简体   繁体   English

Node.js + MongoDB:MongoError:游标被杀死或超时

[英]Node.js + MongoDB : MongoError: cursor killed or timed out

When finding a lot of documents and iterating over them using cursor.nextObject , one by one, the callback eventually returns undefined result and error MongoError: cursor killed or timed out . 当找到大量文档并使用cursor.nextObject迭代它们时,回调最终返回未定义的结果并且错误MongoError: cursor killed or timed out Whole error message is: 整个错误消息是:

[MongoError: cursor killed or timed out] 
name: 'MongoError', 
message: 'cursor killed or timed out'

How to avoid the cursor to be killed? 如何避免光标被杀死?

According to Mongodb's official doc , the optional param timeout can be set to false . 根据Mongodb的官方文档 ,可选的param timeout可以设置为false

db.collection('mycollection').find({}, {timeout:false}, function(err, cursor) {
    if (!err) {
         // Iterate safely on your cursor here
    } else {
        console.log(err);
    }
});

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

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