2012-06-26 6 views
12

Tôi hiện đang sử dụng các cài đặt sau (mà không làm việc) trong mongoid.yml của tôi và tôi đã thêm một cách chính xác các biến môi trường MONGOLAB_URI với môi trường Heroku tôi:Tại sao mongoDB lưu trữ cài đặt uri của tôi cho mongoid.yml không hoạt động chính xác?

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

Tôi cũng thử như sau mà không hoạt động:

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

này cũng không hoạt động:

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

Tôi nhận được lỗi sau trên push 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) 

Tôi đang làm gì sai ở đây? Tôi đã theo các hướng dẫn mongoid.org:

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

Tôi đang sử dụng mongoid 3.0.0.rc

Trả lời

8

Hãy thử ví dụ này

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

production: 
    sessions: 
    default: 
     hosts: 
     - <%= ENV['MONGOLAB_URI'] %> 
     database: testapp_production 
     username: testappuser 
     password: testpassword 
+0

này không làm việc cho tôi. Cảm ơn sự giúp đỡ mặc dù – Goalie

+0

giá trị của ENV ['MONGOLAB_URI'] là gì? – abhas

+0

Tôi đã thay đổi một số mục cho mục đích bảo mật nhưng đây là cách nó trông giống như: 'mongodb: // testappuser: [email protected]: 97321/testapp_production' – Goalie

10

abhas đã không làm việc cho tôi. Đây là những gì cuối cùng làm việc:

production: 
    sessions: 
    default: 
     uri: <%= ENV['MONGOHQ_URI'] %> 
     options: 
     skip_version_check: true 
     safe: true 
+0

Đây là trang trợ giúp trong Heroku yêu cầu nhưng nó không hoạt động. – Francisco

+0

Sao chép dán từ câu trả lời này sẽ không hoạt động do rủi ro trong tên biến môi trường. Nó phải là 'MONGOHQ_URI' và không phải' MONGOHQ_URL'. Ngoài ra, đây là cách truyền URI mongodb (ví dụ: mongodb: // user: mật khẩu @ host: port/db? Params) đến mongoid hoạt động như thời gian viết này. – punnie

+0

Tôi đã thay đổi 'MONGOHQ_URL' thành' MONGOHQ_URI'. Hy vọng điều đó đúng. Tôi đã không sử dụng điều này trong một thời gian – CDeutsch