Skip to content

Instantly share code, notes, and snippets.

@bilke
Created September 6, 2012 07:02
Show Gist options
  • Save bilke/3652342 to your computer and use it in GitHub Desktop.
Save bilke/3652342 to your computer and use it in GitHub Desktop.
Connect to MongoLab with Mongomapper on Heroku
require 'rubygems'
require "mongo_mapper"
regex_match = /.*:\/\/(.*):(.*)@(.*):(.*)\//.match(ENV['MONGOLAB_URI'])
host = regex_match[3]
port = regex_match[4]
db_name = regex_match[1]
pw = regex_match[2]
MongoMapper.connection = Mongo::Connection.new(host, port)
MongoMapper.database = db_name
MongoMapper.database.authenticate(db_name, pw)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment