Mongo Connection Failure

旧城冷巷雨未停 提交于 2019-12-11 15:20:56

问题


I'm new to rails. I would like to push a simple rails application to cloudfoundry and I am getting an error:

 ====> /logs/stderr.log <====
/var/vcap/data/dea/apps/mytestapp-0
-4a068e3fd2b22422bdd29f3762e9bc9b/app/rubygems/ruby/1.9.1/gems/mongo-
1.6.4/lib/mongo/connection.rb:420:in `connect': Fail:27017  (Mongo::ConnectionFailure)

The sample app gemfile:

source 'http://rubygems.org'
gem 'rails', '3.0.5'
gem 'mongo_mapper'
gem 'bson_ext'

mongo.yml:

defaults: &defaults
host: 127.0.0.1
port: 27017

development:
<<: *defaults 
database: cloud_foundry_rails_tutorial_development

test:
<<: *defaults
database: cloud_foundry_rails_tutorial_test

# set these environment variables on your prod server
production: 
host: <%= JSON.parse( ENV['VCAP_SERVICES'] )['mongodb-2.0'].first['credentials']['hostname']  
rescue 'localhost' %>

port: <%= JSON.parse( ENV['VCAP_SERVICES'] )['mongodb-2.0'].first['credentials']['port']    
rescue '27017' %>

database: <%= JSON.parse( ENV['VCAP_SERVICES'] )['mongodb-2.0'].first['credentials']['db'] 
rescue 'cloud_foundry_rails_tutorial' %>

username: <%= JSON.parse( ENV['VCAP_SERVICES'] )['mongodb-2.0'].first['credentials']['username'] 
rescue '' %>

password: <%= JSON.parse( ENV['VCAP_SERVICES'] )['mongodb-2.0'].first['credentials']['password'] 
rescue '' %>

I was able to push to CF last week without any issue but now it doesn't work? Is there something that changed on the CF side? Thanks


回答1:


CloudFoundry.com upgraded from MongoDB 1.8 to 2.0 last week, and that's likely affecting your app. I will be checking with the CF.com engineering team and filing a bug if necessary.

However, since you're manually specifying connection information in mongo.yml, have you disabled auto-config of services? To do so, create the file config/cloudfoundry.yml and add:

autoconfig: false

For more information on auto-config of services in Ruby apps, see http://blog.cloudfoundry.com/2012/03/12/using-cloud-foundry-services-with-ruby-part-1-auto-reconfiguration/



来源:https://stackoverflow.com/questions/12059047/mongo-connection-failure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!