2012 年 6 月 9 日更新:
在 heroku 使用 mongoid 3.0.0.rc 进行设置,请参阅此要点:https ://gist.github.com/2900804
2011 年 1 月 22 日更新:
Uri 现在优先于 mongoid.yml
https://github.com/mongoid/mongoid/issues/issue/266
2010 年 8 月 12 日更新:虽然我在 5 月 6 日从 Jackues Crocker 那里得到了一个接受的答案,但这个问题的某些方面很容易搞砸!它再次发生在我身上,我决定研究 mongoid 源代码。所以,这里是:
目前,主机:端口:名称/数据库:设置优先于uri:设置。因此,由于对localhost:xxxx的请求而不是对flame.local.mongohq.com:xxxx的请求,正在发生非常不具信息性的错误消息
这将打破!
defaults: &defaults
host: localhost <- THIS 'OVERWRITES' host in the uri!
production:
<<: *defaults <- BE CAREFUL WITH WHAT YOU BRING IN. THE host: FROM DEFAULTS WILL BE THE ONE APPLIED, not your uri host.
uri: <%= ENV['MONGOHQ_URL'] %>
通过删除主机:默认值和/或删除<<: *defaults来修复它
原始问题:
我在heroku为mongodb添加了mongoHQ插件。它崩溃了:
connect_to_master': failed to connect to any given host:port (Mongo::ConnectionFailure)
正如我所见,在线描述(heroku mongohq)更针对 mongomapper。我正在运行 ruby 1.9.1 和带有mongoid的 rails 3-beta 。
我的感觉是有一些东西ENV['MONGOHQ_URL']
,它说 MongoHQ 插件集,但我没有MONGOHQ_URL
在我的应用程序中设置任何地方。我想问题出在我的 mongoid.yml 上?
defaults: &defaults
host: localhost
development:
<<: *defaults
database: aliado_development
test:
<<: *defaults
database: aliado_test
# set these environment variables on your prod server
production:
<<: *defaults
host: <%= ENV['MONGOID_HOST'] %>
port: <%= ENV['MONGOID_PORT'] %>
username: <%= ENV['MONGOID_USERNAME'] %>
password: <%= ENV['MONGOID_PASSWORD'] %>
database: <%= ENV['MONGOID_DATABASE'] %>
它在本地运行良好,但在 heroku 失败,更多堆栈跟踪:
==> crashlog.log <==
Cannot write to outdated .bundle/environment.rb to update it
/disk1/home/slugs/176479_b14df52_b875/mnt/.bundle/gems/gems/rack-1.1.0/lib/rack.rb:14: warning: already initialized constant VERSION
/disk1/home/slugs/176479_b14df52_b875/mnt/.bundle/gems/gems/mongo-0.20.1/lib/mongo/connection.rb:435:in `connect_to_master': failed to connect to any given host:port (Mongo::ConnectionFailure)
from /disk1/home/slugs/176479_b14df52_b875/mnt/.bundle/gems/gems/mongo-0.20.1/lib/mongo/connection.rb:112:in `initialize'
from /disk1/home/slugs/176479_b14df52_b875/mnt/.bundle/gems/gems/mongoid-2.0.0.beta4
/lib/mongoid/railtie.rb:32:in `new'
from /disk1/home/slugs/176479_b14df52_b875/mnt/.bundle/gems/gems/mongoid-2.0.0.beta4/lib/mongoid/railtie.rb:32:in `block (2 levels) in <class:Railtie>'
from /disk1/home/slugs/176479_b14df52_b875/mnt/.bundle/gems/gems/mongoid-2.0.0.beta4/lib/mongoid.rb:110:in `configure'
from /disk1/home/slugs/176479_b14df52_b875/mnt/.bundle/gems/gems/mongoid-2.0.0.beta4/lib/mongoid/railtie.rb:21:in `block in <class:Railtie>'
from /disk1/home/slugs/176479_b14df52_b875/mnt/.bundle/gems/gems/railties-3.0.0.beta3/lib/rails/initializable.rb:25:in `instance_exec'
.....
这一切都在本地工作,包括测试和应用程序。我没有想法......有什么建议吗?
PS:有高声望的人创建标签'mongohq'?