Help translating a 2.x mongoid.yml to a 3.x format

26 views
Skip to first unread message

Daniel Doubrovkine

unread,
Nov 5, 2012, 6:47:47 PM11/5/12
to mon...@googlegroups.com
We have a host list in the environment on Heroku w/ MongoHQ and the 2.x mongoid.yml looked like this:

production:
  <<: *defaults
  <% if ENV['MONGOHQ_HOST_LIST'] %>
  hosts: <%= ENV['MONGOHQ_HOST_LIST'] %>
  read_secondary: <%= !$rails_rake_task %>
  database: <%= ENV['MONGOHQ_DATABASE'] %>
  username: <%= ENV['MONGOHQ_USER'] %>
  password: <%= ENV['MONGOHQ_PASSWD'] %>
  <% else %>
  uri: <%= ENV['MONGOHQ_URL'] || '' %>
  <% end %>

How do I translate the list of hosts with the new format? I'd like to avoid hard-coding it.


--

dB. | Moscow - Geneva - Seattle - New York
dblock.org - @dblockdotorg


Daniel Doubrovkine

unread,
Nov 6, 2012, 10:26:05 AM11/6/12
to mon...@googlegroups.com
This seems to work:

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

Please help improve ;)

Daniel Doubrovkine

unread,
Nov 6, 2012, 10:31:22 AM11/6/12
to mon...@googlegroups.com
And if you want my hack for Rake tasks to only go to the primary server:

consistency: :<%= !$rails_rake_task ? 'eventual' : 'strong' %>

Daniel Doubrovkine

unread,
Nov 9, 2012, 9:25:42 AM11/9/12
to mon...@googlegroups.com
Don't know what I was thinking with YAML-parsing this. It's much simpler with `eval`.

I posted a gist with our updated configuration: https://gist.github.com/4045973
Reply all
Reply to author
Forward
0 new messages