2011-05-11 60 views
2

我最近分叉了https://github.com/fortuity/rails3-mongoid-omniauth並試圖在heroku.com上運行。這是一個應用程序,演示如何在heroku上使用MongoDB(通過MongoHQ)以及OAuth身份驗證。我分叉的代碼快照是https://github.com/jgodse/rails3-mongoid-omniauth/tree/8cb490e660ab1d2d1df0f68312584563f0fd223aHeroku:MongoHQ:連接問題

當我調整了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出):

$ heroku info 
=== jgodse-omniauth-mongoid 
Web URL: http://jgodse-omniauth-mongoid.heroku.com/ 
Git Repo: [email protected]: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 

[email protected] ~/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的日誌說,它仍在試圖連接到本地主機:27017即使我刪除本地主機引用從mongoid.yml。還有什麼我必須做的強制它連接到我的MONGOHQ_URL?

回答

2

在文件mongoid.yml中,我應該使用「MONGOHQ_URL」,但我使用了「MONGHQ_URL」。因此,代碼的行爲與本應該默認的一樣,默認爲localhost。

當我在mongoid.yml中開始使用「MONGOHQ_URL」時,一切正常。