轻便摩托车生产环境的错误

时间:2013-04-08 13:18:34

标签: ruby-on-rails ruby ruby-on-rails-3 mongodb mongoid

这是我的mongoid.yml

development:
  sessions:
    default:
      database: myapp
      # Provides the hosts the default session can connect to. Must be an array
      # of host:port pairs. (required)
      hosts:
        - localhost:27017
      options:
test:
  sessions:
    default:
      database: myapp
      hosts:
        - localhost:27017
      options:
        consistency: :strong
        # In the test environment we lower the retries and retry interval to
        # low amounts for fast failures.
        max_retries: 1
        retry_interval: 0
production:
  sessions:
    default:
      database: remote_database
      username: remote_user
      password: 111111
      hosts: 
        - remotedomain.com:27017
      options:
        safe: true
  options:
    identity_map_enabled: true

我的mongodb数据库与其他服务器不同。问题是当我运行这个命令时:

bundle exec rake environment tire:import CLASS=Cv FORCE=true

我的mongodb服务器位于不同的服务器上,我的rails应用程序具有不同的IP和不同的子域。

所以,如果我运行此命令,mongoid在localhost中找不到mongodb服务器,我在生产服务器中收到错误:

Could not connect to any secondary or primary nodes for replica set <Moped::Cluster nodes=[<Moped::Node resolved_address="127.0.0.1:27017">]>

我需要在我的开发环境中使用我的localhost mongodb数据库,在生产服务器中使用我的remoteserver mongodb dabatase。

我想如何解决此问题

1 个答案:

答案 0 :(得分:2)

感谢Magnuss和Durran。答复是:

rake environment tire:import CLASS='Object' FORCE=true RAILS_ENV=production

添加RAILS_ENV=production并解决问题:)。

谢谢!