views:

704

answers:

3

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?

Thanks,

Jonathan

A: 

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
It looks like that Mongoid implementing ActiveModel makes it seem that it is the way to go. I am going to give it a shot this weekend. I'll report back. Thanks
Jonathan
I went with Mongoid, and ported to an all NoSql approach. Pretty happy with the outcome.
Jonathan
A: 

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.

ramonrails
But dont the models have to inherit from MongoID? That is not possible now cause those models are inheriting from AR right?
never_had_a_name
How does this look?http://blog.memamsa.com/2010/07/09/mixing-in-mongodb
ramonrails
A: 

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
Thanks i'll take a look at that, and post if it was useful.
Jonathan