我的Meteor 1.2.1程序MongoError: cursor killed or timed out
陷入了find().forEach()
循环,因此我发现此页面上的这段代码阻止了此操作:
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 ...
});
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句