ActiveRecord combined with MongoDB

201 views
Skip to first unread message

Charly

unread,
Dec 8, 2009, 3:32:13 PM12/8/09
to MongoMapper
Hi,

Has anyone thought of using mongodb in combination with activerecord.
I thought : wouldn't it be nice to have the best of both worlds or at
least ease the transtion to "nosql". When I started experimenting
datamapper for example, although i loved it I quickly missed AR's
ecosystem. "belongs_to_mongo :user" doesn't seem so difficult to
implement or is it ?

Charly

John Nunemaker

unread,
Dec 9, 2009, 12:47:27 AM12/9/09
to mongo...@googlegroups.com
I've used them in combo. I just make methods instead of associations. It works fine you just have to write some code yourself. I wouldn't recommend using both to ease the transition as that would actually make things more complex. It is doable though.


--
You received this message because you are subscribed to the Google
Groups "MongoMapper" group.
For more options, visit this group at
http://groups.google.com/group/mongomapper?hl=en?hl=en

Kyle Bragger

unread,
Dec 9, 2009, 11:46:06 AM12/9/09
to MongoMapper
I'm using them together for a new project; everything is on heroku/
mongohq, and I'm using authlogic (and therefore AR/postgres), and
everything else is stuffed in mongo. It's pretty nice, but would also
not recommend mixing them too much - I've just done it to leverage
authlogic vs. rolling my own mongo auth layer/extending authlogic.

-Kyle

John Nunemaker

unread,
Dec 9, 2009, 12:44:37 PM12/9/09
to mongo...@googlegroups.com
Once you've written an auth system, I think you would find the creating of an auth system easier than managing mysql and mongo together.

Durran Jordan

unread,
Dec 9, 2009, 4:42:57 PM12/9/09
to mongo...@googlegroups.com
Instead of using authlogic have you looked at using devise? It has mongo_mapper support built in, although I personally haven't tried it yet.

2009/12/9 Kyle Bragger <kyle.b...@gmail.com>

Kyle Bragger

unread,
Dec 10, 2009, 11:46:25 AM12/10/09
to MongoMapper
Ha, I have actually, but I just really, really like authlogic. Or
maybe I'm lazy...

On Dec 9, 12:44 pm, John Nunemaker <nunema...@gmail.com> wrote:
> Once you've written an auth system, I think you would find the creating of
> an auth system easier than managing mysql and mongo together.
>

John Nunemaker

unread,
Dec 10, 2009, 1:44:08 PM12/10/09
to mongo...@googlegroups.com
Haha. Laziness is a virtue. :)

Ryan Michael

unread,
Dec 31, 2009, 5:38:58 PM12/31/09
to MongoMapper
I'd like to second interest in a method of combining the two
approaches. I'm still at the beginning of the Mongo learning curve,
but it seems like some data domains would be better represented in an
SQL database and others would be better represented in a document
store - it would be *really* nice to have a way of using the two
approaches selectively based on which is more appropriate (again,
maybe there's *no* reason to ever use SQL - I don't really know).

Wouldn't it be possible to use separate association namespaces and
include both association types for both MongoMapper and ActiveRecord
classes? Here's some quick examples

1) One-to-many MongoMapper -> ActiveRecord
class Foo < ActiveRecord::Base
many :bars
end

class Bar < MongoMapper::Document
key :foo, ActiveRecordId
end

2) One-to-many ActiveRecord -> MongoMapper
class Foo < ActiveRecord::Base
belongs_to :foo
end

class Bar < MongoMapper::Document
has_many :foos
end

3) Many-to-many ActiveRecord <->MongoMapper
class Foo < ActiveRecord::Base
many :bars, :through => :foobars
end

class Bar < MongoMapper::Document
has_many :foos
end

class Foobars < ActiveRecord::Base
belongs_to :foo
belongs_to :bar
end


In other words, add a 'many' method to ActiveRecord and use 'has_many'
on MongoMapper to refer specifically to ActiveRecord associations.
You'd probably need some magic on the 'belongs_to' method, or maybe a
different name could be used.

I could see some problems happening when chaining (foo.bar.baz.find()
where foo & bar are AR and baz is MM), but this still seems like an
interesting goal to pursue.

-Ryan


On Dec 10, 12:44 pm, John Nunemaker <nunema...@gmail.com> wrote:
> Haha. Laziness is a virtue. :)
>

Lance Carlson

unread,
Dec 31, 2009, 8:48:27 PM12/31/09
to mongo...@googlegroups.com, MongoMapper
I thought one of the ideas behind mongodb is the combines the power of
an RDMS. You can stick indices on the columns in your data you need
access to and lookups become very fast.

Sent from my iPhone

Lance Carlson

unread,
Dec 31, 2009, 8:50:04 PM12/31/09
to mongo...@googlegroups.com, MongoMapper
The only possible merit I could see with being able to access both at
once is for large projects where you'd like to convert over sections
to mongodb or possibly the entire thing but need to do it in several
iterations.

Sent from my iPhone

On Dec 31, 2009, at 5:38 PM, Ryan Michael <ker...@gmail.com> wrote:

Ryan Michael

unread,
Jan 1, 2010, 11:55:49 AM1/1/10
to mongo...@googlegroups.com
Also for writing extensions to projects like Radiant CMS or Spree (which is what I'm working on).  If the objective of MongoMapper is to be a replacement for ActiveRecord, it seems like using the same API as much as possible would be nice.

-Ryan

John Nunemaker

unread,
Jan 1, 2010, 8:54:27 PM1/1/10
to mongo...@googlegroups.com
The goal is not to match AR's API. Where it makes sense I do, but where it doesn't I don't. The goal is to make a sweet mapper for mongo that makes it so we don't miss AR.

Stephen Eley

unread,
Jan 2, 2010, 12:41:16 AM1/2/10
to mongo...@googlegroups.com
"A replacement for ActiveRecord" seems like a terribly limiting and shortsighted objective. ActiveRecord itself wasn't intended to "replace" anything, but to reinvent how things were done. MM will never really come into its own if its goal is simply to duplicate stuff that already exists.

There's already an ActiveRecord adapter for Mongo if that's all you want. I'd much rather see MongoMapper pave new roads than spread a new layer of tar over old ones. 

Ryan Michael

unread,
Jan 2, 2010, 11:23:54 AM1/2/10
to MongoMapper
Sorry - I didn't mean to step on anyone's toes with that last post. I
completely agree that given the differences in how the underlying data
stores work btw SQL and noSQL it doesn't make much sense to try to
wrap an API designed for one around another. I guess what I was
trying to say is that *unless* the objective is to do that, it seems
like allowing associations between instances of the two API's would be
a good idea.

From what I can tell (as I said, still on the beginning of the
learning curve here), MySQL has much more robust ACID support than any
of the noSQL implementations; it doesn't seem unreasonable that some
application would benefit from fine-grained ACID support for some data
types, but be more suitable for a document store with others. And it
doesn't seem unreasonable that associations might exist between these
data types.

From what I've been reading, there seem to be a lot of people coming
to the conclusion that databases are on their way to being
increasingly specialized. It just seems like an important part of
facilitating this type of specialization is providing interfaces
between database types.

-Ryan

On Jan 1, 11:41 pm, Stephen Eley <sfe...@gmail.com> wrote:
> "A replacement for ActiveRecord" seems like a terribly limiting and  
> shortsighted objective. ActiveRecord itself wasn't intended to  
> "replace" anything, but to reinvent how things were done. MM will  
> never really come into its own if its goal is simply to duplicate  
> stuff that already exists.
>
> There's already an ActiveRecord adapter for Mongo if that's all you  
> want. I'd much rather see MongoMapper pave new roads than spread a new  
> layer of tar over old ones.
>
> Have Fun,

> Steve Eley - sfe...@gmail.com -http://twitter.com/SFEleyhttp://escapepod.org-http://sfeley.com


>
> On Jan 1, 2010, at 11:55 AM, Ryan Michael <keri...@gmail.com> wrote:
>
>
>
> > Also for writing extensions to projects like Radiant CMS or Spree  
> > (which is what I'm working on).  If the objective of MongoMapper is  
> > to be a replacement for ActiveRecord, it seems like using the same  
> > API as much as possible would be nice.
>
> > -Ryan
>
> > On Thu, Dec 31, 2009 at 7:50 PM, Lance Carlson  
> > <lancecarl...@gmail.com> wrote:
> > The only possible merit I could see with being able to access both at
> > once is for large projects where you'd like to convert over sections
> > to mongodb or possibly the entire thing but need to do it in several
> > iterations.
>
> > Sent from my iPhone
>

Reply all
Reply to author
Forward
0 new messages