Does anybody replaced the default database engine in Django (+1.10) for MongoDB in the last months? All the info I get in Google is like 6 or 4 years ago.
The most commons results includes mongodb-engine which requires django-nonrel (a really old fork from Django 1.5), or mongoengine, also an outdated library that give many errors, so when you patch one, you get a new one.
I don't know if there is any "new" way to accomplish this.
Does Django support NoSQL databases? ¶ NoSQL databases are not officially supported by Django itself. There are, however, a number of side projects and forks which allow NoSQL functionality in Django.
The three most widely used Database Management Systems for Django are SQLite, MySQL, and PostgreSQL. The Django community and official Django documentation state PostgreSQL as the preferred database for Django Web Apps.
Django is a SQL to mongodb query transpiler. Using django we can use MongoDB as a backend database for our Django project. We don't even need to change the Django ORM.
With several builds and tests using docker to try different combinations of versions, I managed to reach to a stable and working Django MongoDB app using the following versions:
Django==1.10.0
pymongo==2.7.1
six==1.10.0
mongoengine==0.9.0
After installing the needed libraries, edit your settings.py to update or add the following
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.dummy'
}
}
AUTHENTICATION_BACKENDS = (
'mongoengine.django.auth.MongoEngineBackend',
)
from mongoengine import *
connect('database_name', host='host_ip', port=27017)
Change the database name and host ip. It tries to connect to localhost by default if no ip is stated.
Now, running your app should have the database connected and ready for use. Check mongoengine documentation for information on how to use it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With