我在我的Rails应用程序一个蒙戈查询已超时,因为收藏是巨大的。
FbCheckin.where(ext_fb_place_id: self.ext_fb_place_id).all
我从您可以添加一个文件读取timeout
选项,以防止光标从以下消息超时:
Moped::Errors::CursorNotFound: The operation: "GET MORE" failed with error
我尝试了多种方法,包括
FbCheckin.where(ext_fb_place_id: ext_fb_place_id, {:timeout=>false}).all
和
FbCheckin.find(ext_fb_place_id: ext_fb_place_id, {:timeout=>false}).all
但这些都不防止超时光标。
有谁知道我怎样才能使这个查询和收集所有FbCheckins
无光标超时事先?
谢谢
你想要的是将光标超时设置为false时,您要查询的MongoDB。
这里是你可以用mongoid 3做什么:
FbCheckin.where(...).no_timeout.each do |fb_checkin|
"do something with fb_checkin"
end
同时采用蒙戈Ruby驱动程序使用“no_cursor_timeout”选项可以查找查询一起。
这将禁用所有光标超时。 默认情况下,MongoDB中试图杀死这已经闲置超过10分钟,所有游标。
更多信息可以发现在这里 。
mongoid默认会杀了很长一段时间的查询,然后提出这个错误
您可以在mongoid.yml改变raise_not_found_error选项来避免这个错误
例如:
production:
sessions:
default:
database: local
hosts:
- localhost:27017
options:
allow_dynamic_fields: true
raise_not_found_error: false