12

我目前在我的 mongoid.yml 中使用以下设置(不起作用),并且我已将MONGOLAB_URI环境变量正确添加到我的 heroku 环境中:

production:
  sessions:
    default:
      another:
        uri: <%= ENV['MONGOLAB_URI'] %>

我还尝试了以下不起作用的方法:

production:
  uri: <%= ENV['MONGOLAB_URI'] %>

这也不起作用

production:
  sessions:
    default:
      uri: <%= ENV['MONGOLAB_URI'] %>

我在 heroku 推送中收到以下错误:

Running: rake assets:precompile
       There is a configuration error with the current mongoid.yml.
       Problem:
       No database provided for session configuration: :default.
       Summary:
       Each session configuration must provide a database so Mongoid knows where the default database to persist to. What was provided was: {"another"=>{"uri"=>nil}}.
       Resolution:
       If configuring via a mongoid.yml, ensure that within your :default section a :database value for the session's default database is defined.
       Example:
       \_\_development:
       \_\_\_\_sessions:
       \_\_\_\_\_\_default:
       \_\_\_\_\_\_\_\_database: my_app_db
       \_\_\_\_\_\_\_\_hosts:
       \_\_\_\_\_\_\_\_\_\_- localhost:27017
       There is a configuration error with the current mongoid.yml.
       Problem:
       No database provided for session configuration: :default.
       Summary:
       Each session configuration must provide a database so Mongoid knows where the default database to persist to. What was provided was: {"another"=>{"uri"=>nil}}.
       Resolution:
       If configuring via a mongoid.yml, ensure that within your :default section a :database value for the session's default database is defined.
       Example:
       \_\_development:
       \_\_\_\_sessions:
       \_\_\_\_\_\_default:
       \_\_\_\_\_\_\_\_database: my_app_db
       \_\_\_\_\_\_\_\_hosts:
       \_\_\_\_\_\_\_\_\_\_- localhost:27017
       Asset precompilation completed (15.47s)

我在这里做错了什么?我已按照 mongoid.org 的说明进行操作:

http://mongoid.org/en/mongoid/docs/installation.html

我正在使用mongoid 3.0.0.rc

4

3 回答 3

10

abhas 的例子对我不起作用。这就是最终奏效的方法:

production:   
  sessions:
    default:
      uri: <%= ENV['MONGOHQ_URI'] %>
      options:
        skip_version_check: true
        safe: true
于 2012-07-16T13:53:00.840 回答
8

试试这个

ENV['MONGOLAB_URI'] = ds053681.mongolab.com:97321

production:
  sessions:
    default:
      hosts: 
        - <%= ENV['MONGOLAB_URI'] %>
      database: testapp_production
      username: testappuser
      password: testpassword
于 2012-06-27T04:31:46.090 回答
2

来自https://devcenter.heroku.com/articles/mongolab#mongoid-5

production:
  clients:
    default:
      uri: <%= ENV['MONGOLAB_URI'] %>
于 2016-08-10T14:59:43.780 回答