new in development version
One of the main advantage of MongoDB is the ability to insert schemaless documents into the database.
MongoKit now allow to save partially structured documents. For now, this feature must be activated but in a future, this should be default behavior.
To enable schemaless support use the use_schemaless attribute:
@connection.register
class MyDoc(Document):
use_schemaless = True
Setting use_schemaless to True allow to have an unset structure but you still can specify a structure:
@connection.register
class MyDoc(Document):
use_schemaless = True
structure = {
"title": unicode,
"age": int,
}
required_fields = ['title']
MongoKit will raise an exception only if required fields are missing:
>>> doc = connection.tutorial.mongokit.MyDoc({'age':21})
>>> doc.save()
Traceback (most recent call last):
...
StructureError: missed fields : ['title']
>>> doc = connection.tutorial.mongokit.MyDoc({'title':u'Hello World !'})
>>> doc.save()