A heritable class designed for work with mongoengine documents. It streamlines the validation and correction of the raw MongoDB data.
Full documentation not yet developed.
import mongoengine as me
import mongoengine-cleaner as mec
class Post(me.Document, mec.Cleaner):
title = me.StringField(max_length=120, required=True, correction=mec.Str)
tags = me.ListField(me.StringField(), allow_null=False, correction=mec.Skip)
author = me.StringField(required=True, correction="unknown")
import mongoengine as me
import mongoengine-cleaner as mec
def author_check(doc, field_name, good_type_match):
if not good_type_match or doc.author=="":
doc.author = "author missing"
if doc.author is None:
doc.author = "author unknown"
doc.tags.append("anonymous")
return doc
class Post(me.Document, mec.Cleaner):
title = me.StringField(max_length=120, required=True, correction=mec.Str)
tags = me.ListField(me.StringField(), correction=mec.SkipNull)
author = me.StringField(required=True, correction=author_check)
post_list = Post.objects(tags='mongodb').cleaner
other_list = Post.objects(tags='other').cleaner(limit=['title'])
[TBD]
MIT licensed. See the bundled LICENSE file for more details.