问题描述
UPDATE 2012年6月9日:
在heroku中使用mongoid 3.0.0.rc进行安装,请参阅以下要点:
UPDATE 22th Jan 2011:
>Uri现在优先于mongoid.yml
更新2010年8月12日:虽然我从Jackues Crocker得到了可接受的答案,但是这个问题的一些方面使得它很容易搞砸!它又发生在我身上,我决定研究mongoid源代码。所以,这里是:
目前, 主机:端口:名称/数据库:设置在uri上使用PRECEDENCE :设置。因此,由于对 localhost:xxxx 的请求而不是 flame.local.mongohq.com:xxxx,因此发生了非常无意义的错误消息 ;默认 通过删除主机:修改默认值,和/或删除 ORIGINAL Q: 我已经添加了。它崩溃了: 在线说明(运行ruby 1.9.1和rails 3-beta。 我的感觉是说有一些 它可以在本地正常工作,但在heroku上失败,更多堆栈跟踪: 这一切都可以在本地运行,包括测试和应用。我没有想法......任何建议? PS:有高repu的人创建标签'mongohq'? 要在您的项目中使用mongoid master,请在您的Gemfile中设置它。 希望新宝石即将发布这将清理东西。 UPDATE 9th june 2012: Setup with mongoid 3.0.0.rc at heroku, see this gist: https://gist.github.com/2900804 UPDATE 22th jan 2011: Uri now takes precedence in mongoid.yml https://github.com/mongoid/mongoid/issues/issue/266 UPDATE 12th aug 2010: Although I got an accepted answer 6th may from Jackues Crocker, there are aspects of this issue that makes it easy to mess up! It happened to me yet again and I decided to research the mongoid source code. So, here it goes: Currently, host: port: name/database: settings TAKE PRECEDENCE OVER the uri: setting. Hence, the awfully uninformative error message is happening due to a request to localhost:xxxx and not to flame.local.mongohq.com:xxxx This will break! fix it with either removing the host: in defaults, and/or removing the <<: *defaults ORIGINAL Q: I have added the mongoHQ addon for mongodb at heroku. It crashes with : The descriptions online (heroku mongohq) are more directed towards mongomapper, as I see it. I'm running ruby 1.9.1 and rails 3-beta with mongoid. My feeling says that there's something with It works fine locally, but fails at heroku, more stack trace: It all works locally, both tests and app. I'm out of ideas... Any suggestions? PS: Somebody with high repu mind create the tag 'mongohq'? Mongoid (master) now has a URI option in mongoid.yml. So you could do: To use mongoid master in your project, set this in your Gemfile Hopefully a new gem will be released soon which will clean things up. 这篇关于heroku mongohq和mongoid Mongo :: ConnectionFailure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
host:localhost< - 这是'OVERWRITES'主机在uri!
产量:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< uri:<%= ENV ['MONGOHQ_URL']%>
connect_to_master':无法连接到任何给定的主机:端口(Mongo :: ConnectionFailure)
ENV ['MONGOHQ_URL']
,它表示MongoHQ插件集,但我没有设置 MONGOHQ_URL
在我的应用程序中的任何位置。我猜这个问题在我的
mongoid.yml中?
默认值:& defaults
主机:localhost
开发:
<<:* defaults
database:aliado_development
test:
<<:* defaults
database:aliado_test
#在您的prod服务器上设置这些环境变量
生产:
host:<%= ENV ['MONGOID_HOST']%>
port:<%= ENV ['MONGOID_PORT']%>
用户名:<%= ENV ['MONGOID_USERNAME']%>
密码:<%= ENV ['MONGOID_PASSWORD']%>
数据库:<%= ENV ['MONGOID_DATABASE']%>
==> crashlog.log< ==
无法写入过期的.bundle / environment.rb以更新它
/disk1/home/slugs/176479_b14df52_b875/mnt/.bundle/gems/gems/rack-1.1。 0 / lib / rack.rb:14:警告:已经初始化常量VERSION
/disk1/home/slugs/176479_b14df52_b875/mnt/.bundle/gems/gems/mongo-0.20.1/lib/mongo/connection。 rb:435:在`connect_to_master':无法连接到任何给定的主机:端口(Mongo :: ConnectionFailure)
从/disk1/home/slugs/176479_b14df52_b875/mnt/.bundle/gems/gems/mongo-0.20 .1 / lib / mongo / connection.rb:112:在`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< class:Railtie>'
/ block1 .beta4 / lib / mongoid.rb:110:在`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'
... ..
制作:
uri:<%= ENV ['MONGOHQ_URL']%>
gemmongoid,::git => [email protected]:mongoid / mongoid.git
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'] %>
connect_to_master': failed to connect to any given host:port (Mongo::ConnectionFailure)
ENV['MONGOHQ_URL']
, which it says the MongoHQ addon sets, but I haven't set MONGOHQ_URL
anywhere in my app. I guess the problem is in mymongoid.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'] %>
==> 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'
.....
production:
uri: <%= ENV['MONGOHQ_URL'] %>
gem "mongoid", :git => "[email protected]:mongoid/mongoid.git"