2015-11-01 59 views
1

我補充生產數據庫,如下所示:當試圖創建新的客戶端,Mongoid找不到名稱的客戶端配置:「默認」

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

取決於以下docs

我用以下命令創建MONGOHQ_URL

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

但是當我通過heroku run rails c打開控制檯。我有以下幾點:

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) 

我怎樣才能在mongoid.yml文件中添加生產配置中使用Heroku的部署?

+0

有一個可能的重複[here](http://stackoverflow.com/questions/24369990/rails-environment-mongoid-connection-issue) – alexunger

回答

9

他們更新了Mongoid 5中mongoid.yml文件的格式。而不是sessions它需要是clients。還有一些其他的變化,我知道userpassword現在嵌套在選項之下不像以前。有關詳細信息,請參閱Mongoid docs

production: 
    clients: 
    default: 
     ...