mongomapper: All content tagged as mongomapper in NoSQL databases and polyglot persistence
There have been only a few days since I’ve written that (maybe) there are already too may mapping tools for document databases. Then, we’ve heard about Mongomatic: a minimal Ruby mapper for MongoDB. And now it is MongoODM, yet another Ruby mapper for MongoDB that can be found on ☞ GitHub.
Basically, I’ve tried to create an ODM that uses the native query syntax of the Ruby driver, but that was:
- Fully compatible with Rails 3
- Use the Mongo ruby driver syntax over a new syntax (for queries, cursors, indexes management…)
- Allow lazy loading of collections and queries nesting (concatenation of ‘find’ calls) to emulate ActiveRecord 3
- No association methods (for now): Just declare your own methods on models to fetch associated items
- Give support for dirty objects, validations, etc. through ActiveModel 3
- Automanage type conversions and default values
- Keep it as simple as possible
I made sure to ask the author, Carlos Paramio, why a new mapping tool for MongoDB? and what is it different in MongoODM compared to those other 3 MongoDB mapping libraries?
Carlos Paramio: The main reason for me creating this new ODM is that I felt the Mongo Ruby driver and its syntax (which is pretty similar to the native MongoDB syntax) is much more proper and richer than the syntax similar to the popular ActiveRecord ORM for Ruby — which is particularly designed for relational databases. Even if MongoMapper and MongoId are awesome projects, they both share this particular ActiveRecord-like syntax, which sometimes seems a bit forced and it generates weird bugs and unexpected behavior.
I preferred to use the official syntax and instead of writing tons of new code to bring all the other interesting features that you would expect from an Object Mapper (as an extra to the database driver), I used some stable and widely used Ruby libraries to provide: Validations, type conversions, dirty objects, nesting conditions, Rails 3 compatibility, etc.
There is a similar ODM by Ben Myles, who shares this same opinion about how a MongoDB ODM should work. It’s called MongoMatic, and it’s really cool. I think we started to code our ODMs at approximately same time, because we both have published stable versions of them recently (I’m particularly using MongoODM for my own project). MongoMatic doesn’t support some features like dirty objects, nesting conditions or Rails 3 compatibility yet, but it seems to be interesting to follow.
I think some people was expecting a solution like this. Like Kyle Banker has said (and I quote) recently in response to the MongoODM announcement at the mongodb-user mailing list: “Awesome. I love the trend of moving toward a more native MongoDB query syntax. Great to see the surge in new Ruby ODMs, too.”
Now the Ruby world of MongoDB has 4 mapping libraries and it is only the time and users that will decide if all of them are needed.