Node.js + MongoDB:MongoError:cursor killed或timed out [英] Node.js + MongoDB : MongoError: cursor killed or timed out
本文介绍了Node.js + MongoDB:MongoError:cursor killed或timed out的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当查找大量文档并使用 cursor.nextObject
逐个遍历它们时,回调最终会返回未定义的结果和错误 MongoError :cursor killed或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
. Whole error message is:
[MongoError: cursor killed or timed out]
name: 'MongoError',
message: 'cursor killed or timed out'
如何避免游标被杀死? / p>
How to avoid the cursor to be killed?
推荐答案
根据 Mongodb的官方文档,可选参数 timeout
可以设置为 false
。
According to Mongodb's official doc, the optional param timeout
can be set to false
.
db.collection('mycollection').find({}, {timeout:false}, function(err, cursor) {
if (!err) {
// Iterate safely on your cursor here
} else {
console.log(err);
}
});
这篇关于Node.js + MongoDB:MongoError:cursor killed或timed out的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文