Djongo lets you deploy Django apps on a MongoDB and SQL DB cloud server
Simplify Query Creation
Writing query documents can get out of control. Djongo does the heavy lifting of creating query documents for you.
SQL <=> No SQL
Switch between MongoDB and other SQL databases. Limit the impact to your Models and business logic.
Security
Directly saving raw JSON
into the database is scary. Djongo secures and validates the JSON
document before saving.
Rapid Prototyping
Speed up development with schema free models. Enforce protection with evolution.
Djongo
Djongo is a unified approach to database interfacing. It is an extension to the
Django ORM framework but maps python objects to MongoDB documents.
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 browser.
Djongo includes handy UI elements that help represent MongoDB documents on the browser.
Query Creation
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
qs = Entry.objects.filter(author__name='Paul')\
.select_related('blog')
Djongo generates complex, error free, aggregation queries automatically. It takes the relatively simple query on the right and automatically generates the pymongo query document on the left.
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.
Rapid Prototyping
As your data evolves you may wish to enforce a structure to it. The
JSONField
represents documents with no structure, and no validations.
The EmbeddedField
lets you describe the structure which triggers automatic validations at the application level.
Setting enforce_schema = True
in the settings.py
file enables schema checks at the database level.
Installation and Setup
Download and install the latest version of Djongo by running:
pip install djongo
The project directory is where all Djongo settings live. Auto generate the required files by running:
django-admin startproject mysite
You can replace mysite with a name of your choosing.
Go into the root of mysite directory to find the settings.py
file. Add:
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'your-db-name',
}
}
YOU ARE SET! Have fun!