Heroku:MongoHQ:连接问题

时间:2011-05-11 20:44:23

标签: ruby-on-rails-3 heroku localhost mongoid

我最近分叉https://github.com/fortuity/rails3-mongoid-omniauth并尝试在heroku.com上运行。这是一个应用程序,它展示了如何在heroku上使用MongoDB(通过MongoHQ)以及OAuth身份验证。我的分叉代码快照位于https://github.com/jgodse/rails3-mongoid-omniauth/tree/8cb490e660ab1d2d1df0f68312584563f0fd223a

在我调整mongoid.yml以包含URI参数后,删除生产(即heroku)环境的其他参数,然后在heroku.com上启动应用程序,我得到了以下日志(来自heroku日志)。

←[36m2011-05-11T19:00:36+00:00 heroku[web.1]:←[0m Starting process with command: thin -p 41913 -e production -R /home/heroku_rack/heroku.ru start
←[36m2011-05-11T19:00:42+00:00 app[web.1]:←[0m /app/.bundle/gems/ruby/1.9.1/gems/mongo-1.3.0/lib/mongo/connection.rb:494:in connect': Failed to connect to a master node at localhost:27017 (Mongo::ConnectionFailure)
←[36m2011-05-11T19:00:42+00:00 app[web.1]:←[0m from /app/.bundle/gems/ruby/1.9.1/gems/mongo-1.3.0/lib/mongo/connection.rb:632:insetup'
←[36m2011-05-11T19:00:42+00:00 app[web.1]:←[0m from /app/.bundle/gems/ruby/1.9.1/gems/mongo-1.3.0/lib/mongo/connection.rb:101:in initialize'
←[36m2011-05-11T19:00:42+00:00 app[web.1]:←[0m from /app/.bundle/gems/ruby/1.9.1/gems/mongo-1.3.0/lib/mongo/connection.rb:152:innew'
←[36m2011-05-11T19:00:42+00:00 app[web.1]:←[0m from /app/.bundle/gems/ruby/1.9.1/gems/mongo-1.3.0/lib/mongo/connection.rb:152:in from_uri'
←[36m2011-05-11T19:00:42+00:00 app[web.1]:←[0m from /app/.bundle/gems/ruby/1.9.1/gems/mongoid-2.0.1/lib/mongoid/config/database.rb:86:inmaster'
←[36m2011-05-11T19:00:42+00:00 app[web.1]:←[0m from /app/.bundle/gems/ruby/1.9.1/gems/mongoid-2.0.1/lib/mongoid/config/database.rb:19:in configure'
←[36m2011-05-11T19:00:42+00:00 app[web.1]:←[0m from /app/.bundle/gems/ruby/1.9.1/gems/mongoid-2.0.1/lib/mongoid/config.rb:319:inconfigure_databases'
←[36m2011-05-11T19:00:42+00:00 app[web.1]:←[0m from /app/.bundle/gems/ruby/1.9.1/gems/mongoid-2.0.1/lib/mongoid/config.rb:114:in from_hash'
←[36m2011-05-11T19:00:42+00:00 app[web.1]:←[0m from (eval):2:infrom_hash'
←[36m2011-05-11T19:00:42+00:00 heroku[web.1]:←[0m Process exited
←[36m2011-05-11T12:00:43-07:00 heroku[web.1]:←[0m State changed from starting to crashed

我的heroku环境看起来像这样(有一些关键信息xxxx' ed out):

$ heroku info
=== jgodse-omniauth-mongoid
Web URL: http://jgodse-omniauth-mongoid.heroku.com/
Git Repo: git@heroku.com:jgodse-omniauth-mongoid.git
Dynos: 1
Workers: 0
Repo size: 5M
Slug size: 5M
Stack: bamboo-mri-1.9.2
Data size: (empty)
Addons: Basic Logging, MongoHQ MongoHQ Free, Shared Database 5MB
Owner: xxxxxxxx

Jay@JAY-PC ~/rapps/rails3-mongoid-omniauth (master)
$ heroku config --long
BUNDLE_WITHOUT => development:test
DATABASE_URL => postgres://xxxxxxxxxxxx
LANG => en_US.UTF-8
MONGOHQ_URL =>    mongodb://heroku:xxxxxxxxxxxxxxxxxxxxxxxxxxxx.mongohq.com:27098/app527030
RACK_ENV => production
SHARED_DATABASE_URL => postgres://xxxxxxx xxxxxx

heroku日志说它仍在尝试连接到localhost:27017,即使我从mongoid.yml删除了localhost引用。还有什么我必须做的就是强迫它连接到我的MONGOHQ_URL吗?

1 个答案:

答案 0 :(得分:2)

在文件mongoid.yml中,我应该使用“MONGOHQ_URL”,但我使用了“MONGHQ_URL”。因此代码表现得像它应该的那样并且默认为localhost。

当我开始在mongoid.yml中使用“MONGOHQ_URL”时,一切正常。

相关问题