Home > database >  Django DATABASES settings
Django DATABASES settings

Time:12-14

I understand if you connect to your MongoDB database via pymongo, you should remove the DATABASES section in your settings.py file, which I have done, but I get this:

django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value.

Apparently, pymongo does not replace a relational database with MongoDB. It is simply a facility allowing you to access a MongoDB in addition to your regular database; meaning I still need my databases settings...

I know my connection string and database name and collection name, but what should the DATABASES section look like in my settings.py file?

On https://docs.djangoproject.com/en/2.0/ref/settings/#databases and a few other posts and articles, only settings for sqlite3 and postgresql and mysql and oracle are mentioned. I cannot seem to find the right setting for 'ENGINE': 'django.db.backends.mongodb'

How can I use a MongoDB database then? What goes in the xxx.backends.xxx section?

I have tried the following, but I get the same error:

DATABASES = {
    'default': {
        'ENGINE': '',
        'NAME': 'myDBname',
        'USER': 'myUser',
        'PASSWORD': 'myPass',
        'HOST': '127.0.0.1',
        'PORT': '8000',
    }
}

When the method in my views.py file is invoked, control does go into the method but I get an GET http://localhost:8000/methodname/ 500 (Internal Server Error) error.

CodePudding user response:

I recommend using djongo. It actually created to connect Django projects to mongodb.

Also in mongodb official documentation you can read about how to configure and connect to your local or remote db using djongo.

CodePudding user response:

Django depends on a relational database. You'll need to use one of the SQL databases mentioned in the documentation, sqlite is the most lightweight one. You can use Mongo in addition if you want.

  • Related