I keep getting an Mongoid::Errors::InvalidDatabase - Database should be a Mongo::DB, not NilClass
from a padrino app that I've got working on dev locally but which refuses to connect to MongoHQ. I've using padrino 0.9.23 and Mongoid 2.0.0. Stumped as to what is going wrong here.
#database.rb
require 'uri'
if ENV["MONGOHQ_URL"]
mongo_uri = URI.parse(ENV["MONGOHQ_URL"])
ENV['MONGOID_HOST'] = mongo_uri.host
ENV['MONGOID_PORT'] = mongo_uri.port.to_s
ENV["MONGOID_USERNAME"] = mongo_uri.user
ENV['MONGOID_PASSWORD'] = mongo_uri.password
ENV['MONGOID_DATABASE'] = mongo_uri.path.gsub("/", "")
else
host = 'localhost'
port = Mongo::Connection::DEFAULT_PORT
database_name = case Padrino.env
when :development then 'tweetup_dev'
when :production then 'tweetup'
when :test then 'tweetup_test'
end
end
Both insertions via a rake task (to test for db connectivity) and the app trying to pull from the db in heroku continually fail with this error:
2011-04-09T08:02:29+00:00 app[web.1]: Mongoid::Errors::InvalidDatabase
- Database should be a Mongo::DB, not NilClass.:
2011-04-09T08:02:29+00:00 app[web.1]: /app/.bundle/gems/ruby/1.9.1/
gems/mongoid-2.0.0/lib/mongoid/config.rb:195:in `master'
2011-04-09T08:02:29+00:00 app[web.1]: (eval):2:in `master'
I can confirm the database is up and running on MongoHQ and I've created a document via web interface in it via MongoHQ remote connection via the supplied details from heroku config --long details.
Stumped at this point s to what the problem is.
Anybody have any clues or pointers as to what I may be doing wrong here? Have the various config options changed in mongoid as of 2.0.0? I should mention this is the first time I've tried to use MongoHQ with Mongoid.
At this point, I'm about to punt, spin up an Amazon EC2 instance and just use a localhost MongoDB but ultimately running this on heroku and with MongoHQ makes a lot more sense.
thanks for any help, Daryl.