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

1
  • 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. Commented Mar 18, 2020 at 11:54

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

This allows you use your MongoDB in python, without any integration with the Django ORM.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.