1

我将复制添加到我的 mongoid 生产部分,如下所示:

production:
  hosts:
    - - <%= ENV['MONGO_URL1'] %>:<%= ENV['MONGO_PORT'] %>
    - - <%= ENV['MONGO_URL2'] %>:<%= ENV['MONGO_PORT'] %>
  read: :secondary
  username: <%= ENV['MONGO_USERNAME'] %>
  password: <%= ENV['MONGO_PASSWORD'] %>
  database: <%= ENV['MONGO_DATABASE'] %>
  max_retries_on_connection_failure: 10

这在 Heroku 上的生产中有效,但在本地,它导致我的服务器在开始出现错误时失败:

ROOT /Users/bashar/rails-projects/my-project /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/syck.rb:135:in load': syntax error on line 13, col 9: - - :' (ArgumentError) 来自 /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/syck.rb:135:in load' from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/mongoid-2.4.7/lib/mongoid/railtie.rb:83:in block in 来自 /Users/bashar/.rvm/rubies /ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/initializable.rb:30:in instance_exec' from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/initializable.rb:30:in run' 来自 /Users/bashar/.rvm/rubies /ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/initializable.rb:55:in block in run_initializers' from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/initializable.rb:54:in each' 来自 /Users/bashar/.rvm/rubies /ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/initializable.rb:54:in run_initializers' from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/application.rb:96:in 初始化!' 来自 /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/railtie/configurable.rb:30:in method_missing' from /Users/bashar/rails-projects/my-project/config/environment.rb:5:in ' 来自 /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:inrequire' from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in块在 /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223 的要求中:在block in load_dependency' from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:640:in/Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:223 的 new_constants_in' 中:在load_dependency' from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:240:in/Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/application.rb:83 的要求中: in require_environment!' from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/commands.rb:39:in '来自脚本/rails:6:inrequire' from script/rails:6:in'  ~/rails-projects/my-project/ [主]

我正在使用 Rails 3.1.3 Mongo 1.6.2 Mongoid 2.4.9 MongoDB 版本 2.0.2

任何想法?

4

1 回答 1

0

您的配置文件应如下所示:

production:
  hosts:
    - <%= ENV['MONGO_URL1'] %>:<%= ENV['MONGO_PORT'] %>
    - <%= ENV['MONGO_URL2'] %>:<%= ENV['MONGO_PORT'] %>
  read: :secondary
  username: <%= ENV['MONGO_USERNAME'] %>
  password: <%= ENV['MONGO_PASSWORD'] %>
  database: <%= ENV['MONGO_DATABASE'] %>
  max_retries_on_connection_failure: 10

它将被解决为:

hosts: [ 'host1:port1', 'host2:port2']

将主机和端口作为两个不同的东西时,您需要双数组:

hosts: [ ['host1', 'port1'], ['host2', 'port2'] ]
于 2012-05-09T10:04:33.300 回答