Skip to content

StoneMoe/mongoengine_dsl

Repository files navigation

Logo

Release Status

DSL to MongoEngine Q

Features

  • Build your mongoengine query from DSL syntax
  • Convert your data at build time via transform hook

Quickstart

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"

More

Full Documentation: https://stonemoe.github.io/mongoengine_dsl