Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

mongodb - Mongo query using mongoid in rails app causing cursor timeout error

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...