Mongo查询在Rails应用中使用Mongoid导致光标超时错误 [英] Mongo query using mongoid in rails app causing cursor timeout error
问题描述
我的Rails应用程序中有一个mongo查询,由于集合很大,该查询正在超时.
I have a mongo query in my rails app that is timing out because the collection is huge.
FbCheckin.where(ext_fb_place_id: self.ext_fb_place_id).all
我从文档中了解到,您可以添加timeout
选项,以防止光标因以下消息而超时:
I've read from documentation that you can add a timeout
option to prevent the cursor from timing out with the following message:
Moped::Errors::CursorNotFound: The operation: "GET MORE" failed with error
我尝试了几种方法,包括
I've tried several ways including
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
但是这些都不能阻止光标超时.
but none of these prevent the cursor from timing out.
有人知道我如何进行此查询并收集所有FbCheckins
,而无需事先使光标超时?
Does anyone know how I can make this query and gather all the FbCheckins
without the cursor timing out beforehand?
谢谢
推荐答案
您想要的是在查询mongodb时将游标超时设置为false.
What you want is to set the cursor timeout to false when you are querying mongodb.
这是您可以使用蒙古3"做的事情
Here is what you can do with mongoid 3:
FbCheckin.where(...).no_timeout.each do |fb_checkin|
"do something with fb_checkin"
end
这篇关于Mongo查询在Rails应用中使用Mongoid导致光标超时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!