Hi,
I’ve been unable to get an API to stay connected after the Atlas DB instant (M10) it connects to elects a new primary. I’ve tried a number of options in the connection string with no luck so far. The only thing that works is to restart the docker container when the AtlasDB connection falls over.
The furthest I got was by setting my readPreferrence to primaryPreferred. This only partially worked as I was then unable to perform any methods that wrote/changed data. I was only able to read.
I tried the following, which works for reads but not writes after a new primary is elected;
mongodb+srv://:@api-uat-test-cluste.vrwtq.mongodb.net/test?retryWrites=true&replicaSet=atlas-lv2f62-shard-0&readPreferrence=primaryPreferred
This results in the following error when I try to write;
pymongo.errors.ServerSelectionTimeoutError: No primary available for writes
My original connection string was;
mongodb+srv://:@api-uat-test-cluste.vrwtq.mongodb.net/test?retryWrites=true&replicaSet=atlas-lv2f62-shard-0&readPreferrence=Primary
This caused the following error;
No replica set members match selector “Primary()” traceback message
For further context, I’m using the following;
eve==0.7.10
Pymongo==3.12.0
uWSGI==2.0.19.1
Which are all run on an ElasticBeanstalk environment. I’m also using vpc peering to connect my EB to Atlas. Unfortunately I can’t make major changes to the codebase as this is a deployed service and I only have a limited budget to resolve this.
edit: This is not my code so I can’t answer any questions as to why the design choices that were made were made.