【问题标题】:MongoError: cursor killed or timed out - Meteor timeout settings ineffectiveMongoError:光标被杀死或超时 - Meteor 超时设置无效
【发布时间】:2016-07-20 11:34:57
【问题描述】:

我的 Meteor 1.2.1 程序在 find().forEach() 循环中抛出了 MongoError: cursor killed or timed out,所以我发现 this page 说这段代码可以防止:

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

但是,driver docs 和我的 Meteor 说该方法不存在:Object [object Object] has no method 'noCursorTimeout'

根据this comment,Mongo autoReconnect 是 enabled by default 并没有帮助,Meteor forum 甚至 .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 方法会有帮助吗?你试过了吗?
  • cursor.maxTimeMS(5000) 结果为Object [object Object] has no method 'maxTimeMS'。 Windows 10 上的 MongoDB server 3.2 可以理解,但 Meteor 1.2.1 不理解。版本文件说 mongo@1.1.3 所以我会尝试更新它。
  • 重新添加 mongo 包保持 Meteor 版本为 mongo@1.1.3。

标签: javascript mongodb meteor


【解决方案1】:

假设 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 ...
  });
});

【讨论】:

  • 那不是很占内存吗?我该如何处理cursor.forEach
  • myData.forEach() 仅包含小型字典。
  • 或者不是:FATAL ERROR: Evacuation Allocation failed - process out of memory@AppData\Local\.meteor\packages\meteor-tool\1.1.10\mt-os.windows.x86_32\tools\utils\fiber-helpers.js:168。不过,在那之前没有超时。
  • 你可以使用toArray代替each
  • @CeesTimmerman 我已经按照您的建议添加了一个带有each 的示例。
猜你喜欢
  • 2016-08-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-08
  • 1970-01-01
  • 2013-01-05
  • 2012-05-03
  • 2021-10-15
相关资源
最近更新 更多