我将复制添加到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:inload' 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
阻止'来自 /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:ininstance_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
从'跑' /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
来自 /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:inrun_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:in {{1阻止在'require'中 /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:in {{1来自.new_constants_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:in {{1来自 /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 来自script / rails的require' 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
:6: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
'rails~ / rails-projects / my-project / [master]
我正在使用 Rails 3.1.3 Mongo 1.6.2 Mongoid 2.4.9 MongoDB版本2.0.2
有什么想法吗?
答案 0 :(得分: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']
当将host和port作为两个不同的东西时,你需要双数组:
hosts: [ ['host1', 'port1'], ['host2', 'port2'] ]