djangorelational-databasedjango-nonrelnon-relational-database

Using mysql and mongodb together for Django


Can I use both relational-database(eg : mysql) and non-relational database(eg : mongodb) together as bacekend dbs for a Django project? If possible then how?
I use Django version 1.11


Solution

  • Yes, kind of. MongoDB is not supported as a backend for Django's ORM, however, you can use through MongoDB Python.

    What I would do, in this case, is use MySQL as your default database in your DATABASES setting. I would use MySQL for all of my Django ORM functions, and only use MongoDB where I need it. You can then connect to MongoDB for non-ORM connections via Python. See here for connecting to MongoDB via Python: https://api.mongodb.com/python/3.4.0/

    There used to be a Mongo backend - again, without much ORM support - but last I saw, it hasn't been updated in several years: https://github.com/django-nonrel

    Good luck!