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

时间:2015-06-15 22:58:14

标签: javascript node.js mongodb cursor

当找到大量文档并逐个使用cursor.nextObject迭代它们时,回调最终会返回未定义的结果和错误MongoError: cursor killed or timed out。整个错误消息是:

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

如何避免光标被杀?

1 个答案:

答案 0 :(得分:1)

根据Mongodb's official doc,可选参数timeout可以设置为false

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