4

As I said in the title I want to integrate mongoDB next to my Postgres Database in a Django3.0 project.

I used to use djongo* but it seems it's not compatible with the latest version of Django.
What do you think is the best connector to use mongoDB in a Django project ?

*https://github.com/nesdis/djongo

Kimor
  • 532
  • 4
  • 17
  • Do you need to "model" what you have in your MongoDB with models? If you use it next to your main ORM models, maybe it's sufficient to use python connectors: **pymongo** and **mongoengine** might be sufficient then. – dirkgroten Mar 18 '20 at 11:54

1 Answers1

5

Yes you are right django 3.0 is not compatible djongo. You can use mongoengine (pip install mongoengine) to connect mongodb with python. It doesn't integrate with the Django ORM (no models) but allows you to define documents to work with.

Please use below code in your project settings.py file

import mongoengine
import pymongo
MONGODB_HOST = 'mongodb://127.0.0.1:27017'
mongoengine.connect(db='db_name', host=MONGODB_HOST, 
    read_preference=pymongo.ReadPreference.PRIMARY_PREFERRED)
dirkgroten
  • 20,112
  • 2
  • 29
  • 42
Vaibhav Mishra
  • 227
  • 2
  • 11