Nozar Safari
Nozar Safari

Reputation: 505

connect mongodb with djongo (Django)

i try connect to mongodb with djongo after reading githup page of djongo and this find same question here but no answer as well change setting.py like this

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

after run python manage.py makemigrate i get this error:

djongo' isn't an available database backend try using "django.db.backend.XXX" where XXX is one of : "mysql" , "oracle" , "postgresql" , "sqlite3"

mongodb version = 3.4

python version = 3.6.3

djogo == 1.2.38

Upvotes: 0

Views: 3829

Answers (6)

K14
K14

Reputation: 191

python version also matters: for me python 3.8.14 works. Tested with the following dependencies.

Python==3.8.14
Django==3.2.15
djongo==1.3.6
Mongo==3.6
pymongo==3.12.3

I think latest version of djongo with Django 3.x.x works perfect but pymongo, Mongo, and Python must be kept same.

Upvotes: 1

Marcel
Marcel

Reputation: 3258

2022: It seems djongo doesn't work with the latest versions (4.X) of django and pymongo, because I solved the issue with:

django==3.2.14
pymongo[srv]==3.12.3

Upvotes: 1

azhar
azhar

Reputation: 380

i install djongo it works for me with latest version of django my django version is 3.2.7 mython version is 3.8 pip install djongo will install the latest version, in my case the command installed of djongo 1.3.6 by default

and change the DB in settings.py

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

Upvotes: 0

Vijay
Vijay

Reputation: 319

First install djongo

pip install djongo

then next makemigration and migrate

Upvotes: 0

Vaibhav Mishra
Vaibhav Mishra

Reputation: 227

You can use mongoengine to connect django with mongodb and add above line in your settings.py file.

import mongoengine
import pymongo

HOST = 'localhost:27017'

mongoengine.connect(
    db='dbname',
    host=HOST,
    read_preference=pymongo.ReadPreference.PRIMARY_PREFERRED
)

Upvotes: 1

Peyman Mehrabani
Peyman Mehrabani

Reputation: 729

You should downgrade Django version to 2.2.8 and reinstall the project.

Upvotes: 2

Related Questions