How Python MongoDB Toolkit Ming Can Ease Schema Maintenance

jieforest發表於2012-06-13
And now that you're all caught up, let's jump right in with Ming....

Why Ming?

If you've come to MongoDB from the world of relational databases, you have probably been struck by just how easy everything is: no big object/relational mapper needed, no new query language to learn (well, maybe a little, but we'll gloss over that for now), everything is just Python dictionaries, and it's so, so fast!

While this is all true to some extent, one of the big things you give up with MongoDB is structure.

MongoDB is sometimes referred to as a schema-free database. (This is not technically true; I find it more useful to think of MongoDB as having dynamically typed documents. The collection doesn't tell you anything about the type of documents it contains, but each individual document can be inspected.)

While this can be nice, as it's easy to evolve your schema quickly in development, it's easy to get yourself in trouble the first time your application tries to query by a field that only exists in some of your documents.

The fact of the matter is that even if the database cares nothing about your schema, your applicationdoes, and if you play too fast and lose with document structure, it will come back to haunt you in the end. The main reason Ming was created at SourceForge was to deal with just this problem. We wanted a (thin) layer on top of pymongo that would do a couple of things for us:

1. Make sure that we don't put malformed data into the database

2. Try to 'fix' malformed data coming back from the database

So, without belaboring the point of its existence, let's jump into Ming.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-732624/,如需轉載,請註明出處,否則將追究法律責任。

相關文章