I\'ve just started a brand new rails project and the first task I\'m trying to complete is creating an object and having it save within my database. I went through the auto
For a replica set / non-replica-set on MongoHQ:
production:
sessions:
default:
<% if ENV['MONGOHQ_HOST_LIST'] %>
database: <%= ENV['MONGOHQ_DATABASE'] %>
username: <%= ENV['MONGOHQ_USER'] %>
password: <%= ENV['MONGOHQ_PASSWD'] %>
hosts:
<% YAML.parse(ENV['MONGOHQ_HOST_LIST']).value.each do |v| %>
- <%= "#{v[0].value}:#{v[1].value}" %>
<% end %>
<% elsif ENV['MONGOHQ_URL'] %>
uri: <%= ENV['MONGOHQ_URL'] %>
<% end %>
options:
consistency: :eventual
safe: true
Database connections currently cannot be made via URI at this point in mongoid. The format of the mongoid.yml is as follows:
environment:
host: <%= ENV['MONGOID_HOST'] %>
port: <%= ENV['MONGOID_PORT'] %>
username: <%= ENV['MONGOID_USERNAME'] %>
password: <%= ENV['MONGOID_PASSWORD'] %>
database: <%= ENV['MONGOID_DATABASE'] %>
What you will need to do is parse the MongoHQ string into its constituent parts to supply in the mongoid.yml
If you want, someone has cooked up a gist that does this for you here
This is how my production mongoid.yml looks like
<% if ENV['MONGOLAB_URI'] %>
<% uri = URI.parse(ENV['MONGOLAB_URI']) %>
production:
<<: *defaults
sessions:
default:
<<: *default_session
database: <%= uri.path.sub('/','') %>
username: <%= uri.user %>
password: <%= uri.password %>
hosts:
- <%= uri.host %>:<%= uri.port %>
<% end %>
and this works for me