1 comment

[ 2.8 ms ] story [ 10.5 ms ] thread
I believe the original article was pretty much spot on - the problem with suggesting to move to NoSQL is that there are tools that try to be an ORM in those data stores as well (see MongoKit, MongoEngine, MongoMapper, et al) that carry a lot of the same problems as ORMs for SQL databases. NoSQL is not immune to this sort of code-masturbation.

The best solution I've found is to drop all the fancy relational-like features of the ORM (lazy loading, etc) - use the databases native apis to query the data - it requires you to mostly understand what you're doing and your code is explicit in how it's accessing the database. But, objects are nice, so keep that part and use a simple object mapper to map the raw document to an object where it makes sense.

Building a simple object mapper on top of pymongo is actually really easy - I rolled my own in an afternoon - so I get objects where I want them without all the ORM-like crap. It's also really handy for enforcing some sort of schema in a schema-less database - most of the time I want a document to have a fixed set of fields, using the object mapper to enforce this handy and adding a field is easy provided you put a sensible default in the object for documents which won't have that field already.