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)from /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'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'from 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 /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 each'from 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: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からの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の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:innew_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からのrequire' :in'from 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 script / rails:6:inrequire' from script/rails:6:in'〜/ rails-projects / my-project/[マスター]

Rails 3.1.3 Mongo 1.6.2 Mongoid2.4.9MongoDBバージョン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']

ホストとポートを 2 つの異なるものとして指定する場合は、2 つの配列が必要です。

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