New to MongoDB, love it but I need some support with MongoEngine.
I am trying to connect my app to MongoDB as I want to implement a Mongo database. The application works fine with SQL3Lite and I was also able to use Djongo. Yet, I am planning to use MongoEngine models and therefore I am trying to use it as DB Engine.
However, for whatever reason I receive an error settings.
DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details."
Here is what I did:
django-admin startproject projectname
python manage.py startapp appname
Models.py:
from django.db import models
from django.db.models.fields.related import ForeignKey
from django.db.models.query import EmptyQuerySet
from django.contrib.auth.models import User,AbstractUser, UserManager
import datetime
import mongoengine
# Create your models here.
class Project(mongoengine.Document):
projectName = mongoengine.StringField()
Settings.py
import os
from pathlib import Path
import mongoengine
mongoengine.connect(db="testdatabase", host="mongodb+srv://<Username>:<Password>@cluster0.qspqt0a.mongodb.net/?retryWrites=true&w=majority")
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = secretKey
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'api'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'prodash.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'prodash.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.dummy'
}
}
At this point I receive always the same error if:
- I create a superuser
- I migrate data
- I login into the app (All of the above work with SQL3Lite)
My pip list is:
asgiref 3.5.2
certifi 2022.6.15
charset-normalizer 2.1.1
Django 4.1
djangorestframework 3.13.1
dnspython 2.2.1
idna 3.3
mongoengine 0.24.2
pip 22.2.2
pymongo 4.2.0
pytz 2022.2.1
requests 2.28.1
setuptools 63.4.3
sqlparse 0.4.2
urllib3 1.26.12
It might be a typo, but I can’t figure out what I am doing wrong. Please, help.