barnybug/mongokit — comment on commit bffb8ca3b109acef1b723337bacf1f71e8fe8de2
File:  line 0
By barnybug:

Thanks for highlighting mongolite. We really like the validation capabilities of mongokit :-)

I don't see the behaviour you state - CustomTypes behave differently than normal types in the structure.
eg:

import mongokit
c = mongokit.Connection('localhost')
db = c.test

@c.register
class Test(mongokit.Document):
structure = {
'foo': unicode,
'bar': unicode,
}

db.test.insert({'_id': 1})

doc = db.test.Test.get_from_id(1)
doc.validate() # <---- exception at this point

vs

import datetime
class CustomDate(mongokit.CustomType):
mongo_type = unicode
python_type = datetime.datetime
def to_bson(self, value):
"""convert type to a mongodb type"""
return unicode(datetime.datetime.strftime(value,'%y-%m-%d'))
def to_python(self, value):
"""convert type to a python object"""
if value is not None:
return datetime.datetime.strptime(value, '%y-%m-%d')

@c.register
class Foo(mongokit.Document):
structure = {
"date": CustomDate(),
}
default_values = {'date':datetime.datetime(2008, 6, 7)}

# insert a foo document without this field
db.test.insert({'_id': 1})

doc = db.test.Foo.get_from_id(1) # <----- exception at this point
doc.validate()