hyperrjas
hyperrjas

Reputation: 10744

moped errors on production environment

This is my 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

My mongodb database is on other server different. The problem is that when I run this command:

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

My mongodb server is located on a different server from where I have my rails application with a different IP and a different subdomain.

So, if I run this command, mongoid don't find the mongodb server in localhost and I get the error in my production server:

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

I need use my localhost mongodb database in my development environment and my remoteserver mongodb dabatase in production server.

I would like how fix this problem

Upvotes: 1

Views: 311

Answers (1)

hyperrjas
hyperrjas

Reputation: 10744

Thank you to Magnuss and Durran. The response is:

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

Add RAILS_ENV=production and the problem was fixed :).

Thank you!

Upvotes: 2

Related Questions