joe
joe

Reputation: 1026

Mongo Connection Failure

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

Upvotes: 0

Views: 1047

Answers (1)

Glenn Oppegard
Glenn Oppegard

Reputation: 1149

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/

Upvotes: 1

Related Questions