import mongoengine as me
me.connect('test')
class AgeField(me.IntField):
def validate(self, value):
if value < 0:
self.error('must be larger than zero')
class Person(me.Document):
age = AgeField()
try:
Person(age=-2).save()
except me.ValidationError:
pass
else:
1/0
p = Person(age=100).save()
Person.objects.update(set__age=-1)
print Person.objects()[0].age
Here's an example: