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
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
and
FbCheckin.find(ext_fb_place_id: ext_fb_place_id, {:timeout=>false}).all
but none of these prevent the cursor from timing out.
Does anyone know how I can make this query and gather all the FbCheckins
without the cursor timing out beforehand?
Thanks
What you want is to set the cursor timeout to false when you are querying mongodb.
Here is what you can do with mongoid 3:
FbCheckin.where(...).no_timeout.each do |fb_checkin|
"do something with fb_checkin"
end
Use 'no_cursor_timeout' option along with the find query while using Mongo Ruby Driver.
This will disable all cursor timeouts. By default MongoDB tries to kill all cursors which have been inactive for more than 10 mins.
More info can be found here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With