MONGODB CONNECTION :
In a Python Django project, the default database used is typically SQLite. However, if you want to use MongoDB as the database for your Django project, you can do so by integrating Django with MongoDB using the djongo
package. Here's how you can set up Django to use MongoDB as the database:
Install Required Packages :
step 1 :
Install the necessary packages by running the following commands:
$ pip install channels $ pip install django-mongodb-engine $ pip install Djongo $ pip install pymongo $ pip install pytz
step 2 :
Update settings.py :
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'your_mongodb_database_name',
}
}
- Replace
'your_mongodb_database_name'
with the actual name of your MongoDB database.
Step 3:
Create the MongoDB Collection:
- If your MongoDB database is empty, you can create a new collection (table) to store the tasks. This can be done using the Django management command:
python manage.py makemigrations
python manage.py migrate
Step 4:
Run the Application:
- Finally, start the Django development server by running the following command:
With this setup, Django will store data in your MongoDB collection.