DSL to MongoEngine Q
- Build your mongoengine query from DSL syntax
- Convert your data at build time via transform hook
Install
pip install mongoengine_dsl
Use
from mongoengine import Document, StringField
from mongoengine_dsl import Query
class User(Document):
fullname = StringField()
User(fullname="Tom").save()
User(fullname="Dick").save()
User(fullname="Harry").save()
assert User.objects(
Query("fullname: Dick")
).first().fullname == "Dick"
assert User.objects(
Query("fullname: dick", transform={
"fullname": lambda x: x.title()
})
).first().fullname == "Dick"
Full Documentation: https://stonemoe.github.io/mongoengine_dsl