2011-11-18 69 views
0

我已经安装了couchdb数据库使用couchrest一个ruby on rails应用程序中使用。添加属性CouchDB的

现在数据库中有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 

回答

0

要添加您需要加载每个文件,修改它,并保存到数据库中的新属性。你可以使用bulk update api来做到这一点,但仅仅为了100k,我认为这是不值得的额外麻烦。

请发表您的更新脚本,并在发生超时时你得到的回溯。

+0

谢谢... 添加代码和跟踪.. – Pravin