【问题标题】:Node.js + MongoDB : MongoError: cursor killed or timed outNode.js + MongoDB:MongoError:游标被杀死或超时
【发布时间】:2015-06-15 22:58:14
【问题描述】:

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

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

如何避免光标被杀死?

【问题讨论】:

    标签: javascript node.js mongodb cursor


    【解决方案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);
        }
    });
    

    【讨论】:

    • 根据您参考的文档,这已经是默认值:timeout {Boolean, default:false}, specify if the cursor can timeout.
    猜你喜欢
    • 1970-01-01
    • 2016-08-25
    • 1970-01-01
    • 1970-01-01
    • 2015-03-28
    • 1970-01-01
    • 2011-05-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多