Question

I am trying to use MongoHQ with my rails app which uses mongoid. I want to host the app at heroku. From the guide on heroku website, I should add this to my mongoid.yml:

production:
  sessions:
    default:
      uri: <%= ENV['MONGOHQ_URL'] %>
      options:
        skip_version_check: true
        safe: true

My question is, do I have to replace <%= ENV['MONGOHQ_URL'] %> with the URI of the following format:

MONGOHQ_URL: mongodb://<user>:<pass>@hatch.mongohq.com:10034/app003132345

I try replacing it and not replacing it. Either way, I got this error in the log (plus a bunch more, but I suspect this one).

MOPED: Could not resolve IP address for <myusername>

Are there anything else besides, adding this to mongoid.yml and add add-on for mongoHQ in heroku?

Was it helpful?

Solution

<%= ENV['MONGOHQ_URL'] %> is calling a value from the environment. If this were on your local machine you would have to enter the url in your environment.

However, Heroku is awesome and handles this for you! So all you need to do is use that code in your mongoid.yml. If you need to get the url to run your rails app in production on your local machine you can perform

heroku config --app your-app-here

This will print out all of the variables in your heroku environment for this app, including 'MONGOHQ_URL'. You can then copy this url (which will have the user and password filled out, so be careful about security!), and put it in your local environment by typing

export MONGOHQ_URL = url_from_heroku

This will keep the variable until you close your terminal session. However you can always have that variable defined if you add that line to your ~/.bash_rc file (or whatever your bash profile is)

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top