20

I am considering using MongoDB (mongo-mapper) for a portion of my rails application. I am not ready to go whole hog MongoDB because there are too many useful gems that depend on a traditional DB.

That being said there are parts of my application that would be great to leverage a document database.

Has anyone had success mixing the two approaches? How do you link activerecord models with mongomapper models?

Arslan Ali
  • 17,418
  • 8
  • 58
  • 76
Jonathan
  • 16,077
  • 12
  • 67
  • 106
  • Which gems are you thinking of? I am currently migrating my app from MySQL to MongoDB. I was thinking of doing a hybrid approach like yours, but the more I learned about MongoDB the more I realized that I would have huge benefits (in my case) for just migrating everything. Some of the gems you wish to leave behind might actually not be necessary in the NoSQL world. – Chris Garrett Apr 22 '10 at 12:35
  • This is what I am using now: acts_as_versioned, formtastic, devise, paperclip, cancan. I *think* a lot of these will need significant tweaking to get to work with mongo – Jonathan Apr 22 '10 at 12:46
  • 1
    Devise and paperclip both work with Mongoid. Devise used to work with MongoMapper but I think they took it out. I dunno about cancan, but Mongoid has some basic versioning support: http://mongoid.org/docs/extras – MrKurt Apr 22 '10 at 14:13

3 Answers3

9

MongoMapper doesn't implement ActiveModel yet, but I think there are a few forks on github that do. You could use Mongoid instead (which does) and your relationships between Mongoid docs and ActiveRecord entries would just magically work. I know a number of people are doing that.

That said, I wouldn't want to mix them unless I absolutely had to have an RDBMS for some reason.

MrKurt
  • 5,080
  • 1
  • 23
  • 22
3

Here a presentation about this issue: http://nosql.mypopescu.com/post/541657350/presentation-blending-nosql-and-sql-at-confoo

I don't know ROR so I can't judge it is a good presentation.

TTT
  • 2,365
  • 17
  • 16
2

http://railscasts.com/episodes/194-mongodb-and-mongomapper http://www.mongodb.org/display/DOCS/Object+Mappers+for+Ruby+and+MongoDB http://www.mongodb.org/display/DOCS/MongoDB+Data+Modeling+and+Rails http://www.mongodb.org/display/DOCS/Ruby+Language+Center

You need to mixin mongomapper with the model class This gives you freedom to define the key-value pairs other than activerecord

include MongoMapper::Document

Dead simple I think.

Ram on Rails
  • 1,299
  • 11
  • 25