Skip to main content

Application to enhance performance by mongodb engine

Project description

Django MongoEngine

This package, unlike Django-MongoEngine or Djongo, doesn't aim on changing SQL role in Django. Writing backend for NoSQL database is not trivial. Here MongoDB is used as helper database, to increase performance.


To install the package by pip run following command

# From Github
$ pip install git+


To start using the package, add djmongoengine to INSTALLED_APPS and define MONGODB_DATABASES



    "default": {
        "name": "dbname",
        "host": '',
        "port": 27017,
        "tz_aware": True,
        # "username": "user",
        # "password": "pass"

Package provides mixin for document schema and connector


class DocumentMixin:
    def UpdateOne(cls, instance):
        # updates document in MongoDB, which corresponeds to django instance

    def from_instance(cls, instance):
        # create mongoengine document based on django instance

We assume that django is stored in ID, since id returns _id from mongodb. In the example, we provide basic example to define mongoengine schema, based on django models

# myapp/

class Category(models.Model):
    title = models.CharField(max_length=50, unique=True)
    alias = models.CharField(max_length=50)

# myapp/

class Category(EmbeddedDocument):

    ID = fields.IntField()

    title = fields.StringField()
    alias = fields.StringField()

    def from_instance(cls, instance):

        return cls(, title=instance.title, alias=instance.alias)

In and are defined functions and signals to sync changes in django to mongodb.


GraphQL is not directly connected with the package, but documentation for graphene is not beginner friendly. There are graphene-django and flask-graphql, but it doesn't allow to explore full potential of graphql and mongodb, so we use graphene-mongo for more diversity. Query is defined in

# myapp/

class Query(graphene.ObjectType):
    articles = graphene.List(ArticleQuery, find=FindInput())

    def resolve_articles(self, info, **kwargs):
        find = kwargs.get("find")


        if find is not None:
            return Article.objects(**find)
        return Article.objects()

schema = graphene.Schema(query=Query)

# myapp/

from .query import schema

def graphql_view(request):

    result = schema.execute(query)

    if result.errors:
        return JsonResponse({"errors": str(result.errors)})

    return JsonResponse({"query":})

Project details

Release history Release notifications

This version


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for djmongoengine, version 1.0
Filename, size File type Python version Upload date Hashes
Filename, size djmongoengine-1.0-py3-none-any.whl (4.2 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size djmongoengine-1.0.tar.gz (3.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page