Skip to content

MakerReduxCorp/mongoengine-cleaner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

mongoengine-cleaner

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.

Declare a Simple Model

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")

Or Write Something Fancy

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)

Invoke the Cleanup Method

post_list = Post.objects(tags='mongodb').cleaner
other_list = Post.objects(tags='other').cleaner(limit=['title'])

Get It Now

[TBD]

License

MIT licensed. See the bundled LICENSE file for more details.

About

A heritable cleaner class that streamlines correct-on-read operations with mongoengine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published