heroku mongohq 和 mongoid Mongo::ConnectionFailure [英] heroku mongohq and mongoid Mongo::ConnectionFailure

查看:17
本文介绍了heroku mongohq 和 mongoid Mongo::ConnectionFailure的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

2012 年 6 月 9 日更新:

UPDATE 9th june 2012:

在 heroku 上使用 mongoid 3.0.0.rc 进行设置,请参阅此要点:https://gist.github.com/2900804

Setup with mongoid 3.0.0.rc at heroku, see this gist: https://gist.github.com/2900804

2011 年 1 月 22 日更新:

UPDATE 22th jan 2011:

Uri 现在优先于 mongoid.yml

Uri now takes precedence in mongoid.yml

https://github.com/mongoid/mongoid/issues/issue/266

2010 年 8 月 12 日更新:虽然我在 5 月 6 日从 Jackues Crocker 得到了一个公认的答案,但这个问题的某些方面很容易搞砸!它再次发生在我身上,我决定研究 mongoid 源代码.所以,这里是:

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:

目前,host: port: name/database: 设置优先于 uri: 设置. 因此,错误信息非常无意义由于对 localhost:xxxx 而不是 flame.local.mongohq.com:xxxx

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

这会坏的!

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'] %>

通过删除默认值中的 host: 和/或删除 <<: *defaults

fix it with either removing the host: in defaults, and/or removing the <<: *defaults

原问题:

我为 mongoHQ 添加了插件="http://www.mongodb.org/display/DOCS/Rails+3+-+Getting+Started" rel="nofollow noreferrer">mongodb 在 heroku.它崩溃了:

I have added the mongoHQ addon for mongodb at heroku. It crashes with :

connect_to_master': failed to connect to any given host:port (Mongo::ConnectionFailure)

在我看来,在线描述(heroku mongohq)更多是针对 mongomapper.我正在使用 mongoid 运行 ruby​​ 1.9.1 和 rails 3-beta.

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.

我的感觉是 ENV['MONGOHQ_URL'] 有一些东西,它说的是 MongoHQ 插件集,但我没有在我的应用程序的任何地方设置 MONGOHQ_URL.我想问题出在我的mongoid.yml ?

My feeling says that there's something with 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 my 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 上失败,更多的堆栈跟踪:

It works fine locally, but fails at heroku, more stack trace:

==> 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'
.....

这一切都在本地运行,包括测试和应用程序.我没有想法...有什么建议吗?

It all works locally, both tests and app. I'm out of ideas... Any suggestions?

PS:有高人气的人创建了标签mongohq"?

PS: Somebody with high repu mind create the tag 'mongohq'?

推荐答案

Mongoid (master) 现在在 mongoid.yml 中有一个 URI 选项.所以你可以这样做:

Mongoid (master) now has a URI option in mongoid.yml. So you could do:

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

要在您的项目中使用 mongoid master,请在您的 Gemfile 中进行设置

To use mongoid master in your project, set this in your Gemfile

gem "mongoid", :git => "git@github.com:mongoid/mongoid.git"

希望很快会发布一个新的 gem 来清理一切.

Hopefully a new gem will be released soon which will clean things up.

这篇关于heroku mongohq 和 mongoid Mongo::ConnectionFailure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆