MongoError:游标被杀死或超时-Meteor超时设置无效

MongoError: cursor killed or timed out - Meteor timeout settings ineffective

本文关键字:超时 -Meteor 设置 无效 游标 MongoError      更新时间:2023-09-26

我的Meteor 1.2.1程序在find().forEach()循环中抛出了MongoError: cursor killed or timed out,所以我找到了这个页面,上面写着这个代码可以防止:

var myCursor = db.users.find().noCursorTimeout()

然而,驱动程序文档和我的Meteor说这个方法不存在:Object [object Object] has no method 'noCursorTimeout'

Mongo autoReconnect是默认启用的,没有任何帮助,Meteor论坛,甚至.find({}, {timeout:false})也没有。

2016-07-20 11:21:37更新启动

2016-07-20 11:37:21调用方法"updateCollections"MongoError时出现异常:游标被杀死或超时

也许Meteor被2016-07-20 09:34:57失败的SOAP调用弄糊涂了?

  "error": {
    "errno": "ETIMEDOUT",
    "syscall": "connect",
    "code": "ETIMEDOUT"
  },

假设maxTimeMS在这种情况下会有所帮助,您可以通过使用rawCollection对象而不是Meteor集合本身来访问它。

很简单:

var rawCollection = Meteor.users.rawCollection();
var cursor = rawCollection.find({}).maxTimeMS(5000);
var myData = fetchCursor(cursor);

其中fetchCursor是一个简单的光纤感知辅助功能,可以这样实现:

var fetchCursor = Meteor.wrapAsync(function fetchCursor (cursor, cb) {
  cursor.toArray(cb);
});

不过,我不确定这种方法是否正是你想要的。

编辑

如果你不需要整个文档阵列,但你想独立处理其中的每一个,那么最好使用each而不是toArray,例如

var fetchCursor = Meteor.wrapAsync(function fetchCursor (cursor, cb) {
  cursor.each(function (err, doc) {
    if (err) return cb(err);
    if (!doc) return cb(null, { done: true }); // no more documents
    // do something with the document ...
  });
});