I am having an unusual problem: I successfully deployed a Django app on the digital ocean app platform but the problem is that whenever I am trying to reach any route that requires database app crashes because of MongoDB connection problem and after some time I see
upstream connect error or disconnect/reset before headers. reset reason: connection termination
When I check the logs I see the ServerSelectionTimeoutError from pymongo
So the first thing I checked is the host URL which is correct because using the same credentials I am able to connect and query data from my local pc by a python program I followed the format:
"mongodb:srv//myusername:mypassword@clustername.mongodb.net/mydbname my password doesn't contain any special characters
In my Django app settings, I put all the required variables to get Django working with MongoDB -I used djongo as an engine
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'stocks',
'HOST': os.getenv("DB_HOST"),
'USER': os.getenv("DB_USERNAME"),
'PASSWORD': os.getenv("DB_PASSWORD")
}
}
All the variables are set correctly I checked in an App platform console
Another thing is that if I run python shell in apps console on digital ocean so directly on a server I get a different error immediately but when accessing from the deployed website it takes some time to get above error:
pymongo.errors.OperationFailure: Authentication failed., full error: {'ok': 0, 'errmsg': 'Authentication failed.', 'code': 8000, 'codeName': 'AtlasError'}
I am still kinda new to web development it's maybe my 5th app and never had any problems connecting to MongoDB so maybe there something I am missing. First time asking a question here thanks anyone in advance any help would be much appreciated :)