Padrino, heroku, mongoid and MongoHQ :: Keep getting nil database error

75 views
Skip to first unread message

Daryl

unread,
Apr 9, 2011, 4:13:08 AM4/9/11
to Padrino Framework
I've got a padrino app I've been running locally with MongoDB and
have
attempted to move it to Heroku using Mongoid 2.0.0 and connect to
MongoHQ (seemed like a good idea). Been absolutely banging my head as
to why this is not working. Mongoid::Errors::InvalidDatabase
- Database should be a Mongo::DB, not NilClass.

#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 in it which works, so absolutely stumped at this
point as to what the problem is. Using heroku config --long gives me
the paramaters for the mongodb anf I can remote connect to it via
MongoHQ to brwose and enter data.

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 local MongoDB.

Davide D'Agostino

unread,
Apr 9, 2011, 4:56:15 AM4/9/11
to pad...@googlegroups.com
Are you sure that u can connect on a remote server? I think heroku firewall block some ports. No?
---
Best Regards,
Davide D'Agostino

Tel. +39 0331 386985
Mobile. +39 349 7079458
Fax. +39 0331 1989106

http://www.lipsiasoft.com

Daryl

unread,
Apr 9, 2011, 6:11:33 AM4/9/11
to Padrino Framework
Should have mentioned, apologies, that I'm using the heroku mongohq
plugin so I'm pretty sure it's not being blocked.

Daryl.


On Apr 9, 6:56 pm, Davide D'Agostino <d.dagost...@lipsiasoft.com>
wrote:

Jacques Crocker

unread,
Apr 10, 2011, 3:51:54 PM4/10/11
to pad...@googlegroups.com
Hey Daryl. I'd recommend using this for your database.rb:

config_file = Padrino.root("config", "mongoid.yml")
if File.exists?(config_file)
  settings = YAML.load(ERB.new(File.read(config_file)).result)[Padrino.env.to_s]
  ::Mongoid.from_hash(settings) if settings.present?
end

Here's a gist configuration that should work well for you: https://gist.github.com/912656
Reply all
Reply to author
Forward
0 new messages