I managed to get it working locally (different cluster, separate settings.py), but not after when deployed to Heroku.
Heroku – automatically adds DATABASE_URL config var with a postgresql, and I cannot remove/edit it.
MongoDB Atlas – I’ve set the MongoDB Atlas cluster to allow IPs from everywhere. And the password has no funny characters.
django production settings.py
DATABASES = { 'default': { 'ENGINE': 'djongo', 'NAME': 'DBProd', 'CLIENT': { 'host': "mongodb+srv://XXX:YYY@ZZZ.pc4rx.mongodb.net/DBProd?retryWrites=true&w=majority", } } }
I ran migrate straight after the deployment and it’s all green OKs
heroku run python manage.py migrate
Everything works functional wise, just that the data are not stored in the MongoDB Atlas cluster. There are lots of posts from various sites on this, but they all have different instructions… Some of the posts I tried to follow:
- https://developer.mongodb.com/how-to/use-atlas-on-heroku/
- Django + Heroku + MongoDB Atlas (Djongo) = DatabaseError with No Exception
- Connecting Heroku App to Atlas MongoDB Cloud service
— A very confused beginner
Advertisement
Answer
For whoever lands on this. Add 'authMechanism': 'SCRAM-SHA-1',
below 'host'
will fix the issue.