Skip to content

Instantly share code, notes, and snippets.

@pedrodelgallego
Created January 4, 2011 13:40
Show Gist options
  • Save pedrodelgallego/764772 to your computer and use it in GitHub Desktop.
Save pedrodelgallego/764772 to your computer and use it in GitHub Desktop.
# mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
settings = URI.parse(ENV['MONGOLAB_URL'] || ENV['MONGOHQ_URL'] || 'mongodb://localhost/app_test')
database_name = settings.path.gsub(/^\//, '')
Mongoid.configure do |config|
config.master = Mongo::Connection.new(settings.host, settings.port).db(database_name)
config.master.authenticate(settings.user, settings.password) if settings.user
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment