views:

270

answers:

1

I have a rails app using mongodb through mongomapper and all is well. The problem is... I'm going to want to use erlang to do some background processing and I want to update the same mongo/mongomapper models with the results of this processing. What's the best way to share model definitions between the two apps (rails and erlang) and remain sane? Seems like it would be problematic to try to manage them separately if they're both accessing the same records. If there's no "good" way, am I simply approaching this the wrong way?

Additional info: I was originally doing the background processing using starling/workling clients. This is nice since I could use all of the same rails models and code. Performance was terrible though so I'm looking to erlang to solve some of the efficiency problems. It's a large amount of data being processed, but it can be easily processed in parallel.

I'm trying to avoid using erlang as the sole mediator between mongodb and rails through a rest or thrift interface.

Edit: I wanted to shine a little more light on this. The erlang processing will need to know a little bit about the models beforehand. I'm basically using erlang to pull data from other places and fill in details of the model objects. So, for example, there may be a description field that I'm scraping from an xml file using xmerl_xpath:string("//description/text()"). I need to be able to add methods like this that will act upon fields of the model.

+1  A: 

MongoDB has two community-supported Erlang drivers (erlmongo and emongo). Accessing your mongodb through those drivers will give you native Erlang objects.

Ruby -> MongoMapper -> Mongo ruby driver -> MongoDB -> (emongo | erlmongo) -> Erlang

tobym
Thanks for your response. This setup was basically what I was considering but it feels like model definitions would be brittle since they have to be defined separately for both rails and erlang. (This feels especially daunting since I'm using GridFS.) This also means that erlang and rails would be tightly coupled, but maybe that's not a bad thing?The only alternative I can think of involves making erlang the sole interface to MongoDB and accessing it from Rails using a private API (through REST or perhaps Thrift) but I'd miss the functionality MongoMapper provides for free.Thoughts?
Mark Quezada