When attempting to create the new client, Mongoid could not find a client configuration for the name: 'default'

3.3k views Asked by At

I added production database as the following:

production:
  sessions:
    default:
      uri: <%= ENV['MONGOHQ_URL'] %>
      options:
        consistency: :strong
        max_retries: 1
        retry_interval: 0

Depend on the following docs.

And I created MONGOHQ_URL by the following command:

heroku config:add MONGOHQ_URL=mongodb://user:[email protected]:port/db_name

But when I open the console by heroku run rails c. I got the following:

There is a configuration error with the current mongoid.yml.

message:
  No clients configuration provided.
summary:
  Mongoid's configuration requires that you provide details about each client that can be connected to, and requires in the clients config at least 1 default client to exist.
resolution:
  Double check your mongoid.yml to make sure that you have a top-level clients key with at least 1 default client configuration for it. You can regenerate a new mongoid.yml for assistance via `rails g mongoid:config`.

 Example:
   development:
     clients:
       default:
         database: mongoid_dev
         hosts:
           - localhost:27017

Loading production environment (Rails 4.2.4) 

How can I add production configuration in mongoid.yml file to deploy using heroku ?

1

There are 1 answers

0
Ryan On

They updated the format of the mongoid.yml file in Mongoid 5. Instead of sessions it needs to be clients. There are a few other changes too, I know user and password are now nested under options unlike before. See the Mongoid docs for details.

production:
  clients:
    default:
      ...