Mongo查询在Rails应用中使用Mongoid导致光标超时错误 [英] Mongo query using mongoid in rails app causing cursor timeout error

查看:47
本文介绍了Mongo查询在Rails应用中使用Mongoid导致光标超时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆