Install djongo

{code}

pip install djongo

 {/code}

 

Create your project dir

{code}

mkdir chillzeeTest

 {/code}

 

Go to your project directory and set up django project.

{code}

cd chillzeeTest

django-admin startproject ChillzeeTestSite

{/code}

Five Minutes Technology - Using MongoDB with Django framework via Djongo

 

Edit settings.py and update database settings.

{code}

DATABASES = {

    'default': {

        'ENGINE': 'djongo',

        'NAME': 'chillzeeproject',

    }

}

{/code}

Five Minutes Technology - Using MongoDB with Django framework via Djongo

 

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

{code}

python manage.py migrate

{/code}

 

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.

{code}

show dbs

{/code}

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.

{code}

use chillzeeproject

show collections

{/code}

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!