gpt4 book ai didi

ruby - 找不到 Mongo Ruby 驱动程序游标错误

转载 作者:可可西里 更新时间:2023-11-01 09:12:58 26 4
gpt4 key购买 nike

我使用 ruby​​ 驱动程序从 mongodb 中找到文档,将它们收集到数组中并迭代它们以更新与以下代码中相同的文档:

crawlarray = @@mongoclient[:crawlarray].find({searchresults:[]},:timeout => false).limit(500)
crawlarray.each do |elm|
finalsearchstring = elm['searchstring']
if elm["searchresults"].blank?
ap "SEARCHING: #{finalsearchstring}"
results = searchG(finalsearchstring)
elm["searchresults"] = results
@@mongoclient[:crawlarray].update_one({"_id" => elm['_id']}, elm)
else
ap "ALREADY SEARCHED: #{finalsearchstring}"
end
end

有 90K 条记录,但如您所见,我只得到 500 条记录,以免出现错误。每次,在大约 150 次迭代后,我都会收到此错误;

D, [2016-08-02T22:32:08.853065 #10098] DEBUG -- : MONGODB | 127.0.0.1:27017 | posluga-dev.getMore | FAILED | Cursor not found, cursor id: 463388278686 (43) | 0.008009s
/Users/apple/.rvm/gems/ruby-2.2.1/gems/mongo-2.2.7/lib/mongo/operation/result.rb:256:in `validate!': Cursor not found, cursor id: 463388278686 (43) (Mongo::Error::OperationFailure)
from /Users/apple/.rvm/gems/ruby-2.2.1/gems/mongo-2.2.7/lib/mongo/operation/executable.rb:36:in `block in execute'
from /Users/apple/.rvm/gems/ruby-2.2.1/gems/mongo-2.2.7/lib/mongo/server/connection_pool.rb:107:in `with_connection'
from /Users/apple/.rvm/gems/ruby-2.2.1/gems/mongo-2.2.7/lib/mongo/server/context.rb:63:in `with_connection'
from /Users/apple/.rvm/gems/ruby-2.2.1/gems/mongo-2.2.7/lib/mongo/operation/executable.rb:34:in `execute'
from /Users/apple/.rvm/gems/ruby-2.2.1/gems/mongo-2.2.7/lib/mongo/cursor.rb:163:in `block in get_more'
from /Users/apple/.rvm/gems/ruby-2.2.1/gems/mongo-2.2.7/lib/mongo/retryable.rb:51:in `call'
from /Users/apple/.rvm/gems/ruby-2.2.1/gems/mongo-2.2.7/lib/mongo/retryable.rb:51:in `read_with_retry'
from /Users/apple/.rvm/gems/ruby-2.2.1/gems/mongo-2.2.7/lib/mongo/cursor.rb:162:in `get_more'
from /Users/apple/.rvm/gems/ruby-2.2.1/gems/mongo-2.2.7/lib/mongo/cursor.rb:88:in `each'
from /Users/apple/.rvm/gems/ruby-2.2.1/gems/mongo-2.2.7/lib/mongo/collection/view/iterable.rb:44:in `each'

谁能帮我解决一下?

最佳答案

在使用 Mongo Ruby 驱动程序时,使用 'no_cursor_timeout' 选项和查找查询。

这将禁用所有游标超时。默认情况下,MongoDB 会尝试杀死所有处于非事件状态超过 10 分钟的游标。有关更多信息,请查看此 post .

关于ruby - 找不到 Mongo Ruby 驱动程序游标错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38730077/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com