(Reading time: 2 - 3 minutes)

Install djongo

 
 
 
pip install djongo
 
 
 

 

Create your project dir

 
 
 
mkdir chillzeeTest
 
 
 

 

Go to your project directory and set up django project.

 
 
 
cd chillzeeTest
 
 
django-admin startproject ChillzeeTestSite
 
 
 

Five Minutes Technology - Using MongoDB with Django framework via Djongo

 

Edit settings.py and update database settings.

 
 
 
DATABASES = {
 
 
    'default': {
 
 
        'ENGINE': 'djongo',
 
 
        'NAME': 'chillzeeproject',
 
 
    }
 
 
}
 
 
 

Five Minutes Technology - Using MongoDB with Django framework via Djongo

 

Run the following command to apply database changes to your django project

 
 
 
python manage.py migrate
 
 
 

 

Visit http://127.0.0.1:8000/ to make sure that your django project is up and running

 

Go to MongoDB and see if the database has been created by django.

 
 
 
show dbs
 
 
 

Five Minutes Technology - Using MongoDB with Django framework via Djongo

 

In our example, django has created the chillzeeproject database.

We will now see the collections to make sure that every thing went fine.

 
 
 
use chillzeeproject
 
 
show collections
 
 
 

Five Minutes Technology - Using MongoDB with Django framework via Djongo

 

Now you can update your models.py file to work on your new mongoDB database, just as you would do with any other database like postgres or mysql.

So that’s it friends! As you could see connecting MongoDB to django has become much simpler now.

Long live open source community!

Oxygen
Author: Oxygen
Other articles by this author

Chillzee Tag Cloud

Let's Socialize

About Chillzee

Chillzee.com is an entrepreneurship portal.

The site provides informative topics on Organizational and Strategic needs.