Python Object to MongoDB Document Mapping Framework

Security

Security

Directly saving raw JSON into the database is scary. Djongo secures and validates the JSON document before saving.

Simplify Query Creation

Simplify Query Creation

Writing query documents can get out of control. Djongo does the heavy lifting of creating query documents for you.

Web Interface

Web Interface

Access and modify MongoDB through the web browser.

Support

Support

Get support for queries on MongoDB document modeling.

Learn More

Rapid Prototyping

Rapid Prototyping

Speed up app development and execution with schema free models. Enforce different levels of schema protection based on your data evolution.

Admin MongoDB

Third Party Packages

Modules that help interface your MongoDB data with other popular packages.

Djongo Djongo is an extension to the traditional Django ORM framework. It maps python objects to MongoDB documents, a technique popularly referred to as Object Document Mapping or ODM.

Constructing queries using Djongo is much easier compared to writing lengthy Pymongo query documents. Storing raw JSON emitted by the frontend directly into the database is scary. Djongo ensures that only clean data gets through.

You no longer need to use the shell to inspect your data. By using the Admin package, you can access and modify data directly from the web browser. Djongo carries handy UI elements that help represent MongoDB documents on the browser.

Security and Integrity Checks

def script_injection(value):
    if value.find('<script>') != -1:
        raise ValidationError(_('Script injection in %(value)s'),
                              params={'value': value})

class Entry(models.Model):
    homepage = models.URLField(validators=[URLValidator,
                                           script_injection])

Djongo performs checks on data fields before they are saved to the database.

Define custom validators or use builtin validators to check the data. Validation is triggered prior to writing to the database.

Running integrity checks and field value validators ensures protect from garbage data.

Query Creation

Djongo

qs = Entry.objects.filter(author__name='Paul')\
                  .select_related('blog')

PyMongo

self.db['entry'].aggregate(
    [{
        '$match': {
          'author_id': {
            '$ne': None,
            '$exists': True
          }
        }
      },
      {
        '$lookup': {
          'from': 'author',
          'localField': 'author_id',
          'foreignField': 'id',
          'as': 'author'
        }
      },
      {
        '$unwind': '$author'
      },
      {
        '$lookup': {
          'from': 'blog',
          'localField': 'blog_id',
          'foreignField': 'id',
          'as': 'blog'
        }
      },
      {
        '$unwind': {
          'path': '$blog',
          'preserveNullAndEmptyArrays': True
        }
      },
      {
        '$addFields': {
          'blog': {
            '$ifNull': ['$blog', {
              'id': None,
              'title': None
            }]
          }
        }
      },
      {
        '$match': {
          'author.name': {
            '$eq': 'Paul'
          }
        }
      }, 
      {
        '$project': {
          'id': True,
          'blog_id': True,
          'author_id': True,
          'content': True,
          'blog.id': True,
          'blog.title': True
        }
      }]

Djongo generates complex, error free, aggregation queries automatically. It takes the relatively simple query on the left and generates the pymongo query document on the right.

Rapid Prototyping

Djongo

As your data evolves you may wish to enforce a structure to it. The JSONField represents documents with no structure, while setting enforce_schema = True in the settings.py file enables checks to the data.

Next, the EmbeddedField lets you describe the structure which triggers automatic validations at the application level.

Finally, you can enable schema checks at the database level. MongoDB schema documents are created inside a model. Setting enforce_schema = True in the settings.py file enables schema checks on the stored collections.

Get Started