0

我已经设置了一个couchdb数据库,用于使用couchrestruby on rails的应用程序。

现在数据库有大约 10 万条记录,我想添加一个字段来以整数格式存储时间戳。
尝试通过循环更新它会导致请求超时。

向 couchdb 添加新字段/属性的最佳方法是什么?

代码

pages = Page.all
pages.each do |p|
  p.update_attributes(:created_at_to_i => p.created_at.to_i)
  puts p.created_at_to_i.inspect
end

痕迹

>> Page.update_timestamp
RestClient::RequestTimeout: Request Timeout
    from /usr/local/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient/request.rb:184:in `transmit'
    from /usr/local/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient/request.rb:64:in `execute'
    from /usr/local/lib/ruby/gems/1.8/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute'
    from /usr/local/lib/ruby/gems/1.8/gems/couchrest-1.1.2/lib/couchrest/rest_api.rb:89:in `execute'
    from /usr/local/lib/ruby/gems/1.8/gems/couchrest-1.1.2/lib/couchrest/rest_api.rb:45:in `get'
    from /usr/local/lib/ruby/gems/1.8/gems/couchrest-1.1.2/lib/couchrest/database.rb:260:in `view'
    from /usr/local/lib/ruby/gems/1.8/gems/couchrest-1.1.2/lib/couchrest/design.rb:52:in `view_on'
    from /usr/local/lib/ruby/gems/1.8/gems/couchrest_model-1.1.2/lib/couchrest/model/views.rb:142:in `fetch_view'
    from /usr/local/lib/ruby/gems/1.8/gems/couchrest_model-1.1.2/lib/couchrest/model/views.rb:135:in `fetch_view_with_docs'
    from /usr/local/lib/ruby/gems/1.8/gems/couchrest_model-1.1.2/lib/couchrest/model/views.rb:104:in `view'
    from /usr/local/lib/ruby/gems/1.8/gems/couchrest_model-1.1.2/lib/couchrest/model/document_queries.rb:12:in `all'
    from /var/www/monitoring_couch/app/models/page.rb:309:in `update_timestamp'
    from (irb):2
4

1 回答 1

0

要添加新属性,您需要加载每个文档,对其进行修改,然后将其保存回数据库。您可以使用批量更新 api来做到这一点,但只需 100k,我认为这不值得额外的麻烦。

请发布您的更新脚本和超时发生时获得的回溯。

于 2011-11-18T12:11:34.847 回答