MongoError:光标被杀死或超时 - Meteor 超时设置无效 [英] MongoError: cursor killed or timed out - Meteor timeout settings ineffective

查看:46
本文介绍了MongoError:光标被杀死或超时 - Meteor 超时设置无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Meteor 1.2.1 程序在 find().forEach() 循环中抛出了 MongoError: cursor Killed or timed,所以我找到了 此页面 表示此代码可防止:

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

但是,驱动程序文档 和我的 Meteor 说该方法没有存在:Object [object Object] 没有方法 'noCursorTimeout'

Mongo autoReconnect 默认启用并且没有帮助,流星论坛也没有,或甚至 .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 调用弄糊涂了?

错误":{"errno": "ETIMEDOUT",系统调用":连接",代码":超时"},

解决方案

假设 maxTimeMS 在这种情况下会有所帮助,您可以通过使用 rawCollection 对象而不是流星收集本身.

很简单:

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(函数(错误,文档){如果(错误)返回 cb(错误);if (!doc) return cb(null, { done: true });//没有更多的文件//对文档做一些事情...});});

My Meteor 1.2.1 program threw MongoError: cursor killed or timed out in a find().forEach() loop, so i found this page that says this code prevents that:

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

However, the driver docs and my Meteor say that method doesn't exist: Object [object Object] has no method 'noCursorTimeout'

Mongo autoReconnect is enabled by default and didn't help, nor did the Meteor forum, or even .find({}, {timeout:false}) according to this comment.

2016-07-20 11:21:37 Update started

2016-07-20 11:37:21 Exception while invoking method 'updateCollections' MongoError: cursor killed or timed out

Maybe Meteor got confused by the failed SOAP call at 2016-07-20 09:34:57?

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

解决方案

Assuming maxTimeMS would help in this case you can access it by working with rawCollection object instead of the Meteor collection itself.

It's quite simple:

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

Where fetchCursor is a simple fiber-aware helper function that can be implemented like this:

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

Though, I am not sure if this method is exactly what you're looking for.

Edit

If you don't need the entire array of documents but you want to process each one of them independently it may be better to use each instead of toArray, e.g.

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

这篇关于MongoError:光标被杀死或超时 - Meteor 超时设置无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆