I’ve got an existing production Ruby/Rails app that I want to migrate to MongoDB over time, as time permits, because it’s not an option to just rewrite it all at one time. I’d love to be able to just deprecate my old classes as I get to them. I plan to use MongoMapper. I can’t find an example where anyone explains how to set up the database config files to allow connection to both data stores within one app.
FWIW, I’m using Rails 3. I appreciate the help.
Include your mongo_mapper gem in you Gemfile. Then in the models that you slowly want to start migrating over to MongoMapper, you just include this in your model:
here is an example of a Mongo publisher model
My user model (postgres):
The nice thing about this is that all of your other models still use ActiveRecord so you can use 2 different databases till everything is migrated over to Mongo. This is an example from what I’m using. Large data aggregations using MongoMapper, and User model using postgres (app hosted on Heroku)
For my setup I dumped config stuff in my config.yml
and created an initializer that differentiates between the 2 DBs:
/initializers/database.rb