heroku config:set MONGOHQ_URL=mongodb://[user]:[password]@[host].mongohq.com:10007/[database]
I have slightly modified connect function (shown below). I supply a default to the local copy of MongoDB. I also corrected the check for db.password.nil?
def connect
return @db if @db
uri = 'http://localhost:27017/mydb'
if( ENV.has_key?('MONGOHQ_URL')) then
uri = ENV['MONGOHQ_URL']
end
db = URI.parse(uri)
db_name = db.path.gsub(/^\//, '')
@db = Mongo::Connection.new(db.host, db.port).db(db_name)
@db.authenticate(db.user, db.password) unless (db.user.nil? || db.password.nil?)
@db
end
No comments:
Post a Comment