I’m currently working on a project that uses a Flask App running in a Docker container hosted on Elastic Beanstalk. The API falls over every 1-5 weeks with a “No replica set members match selector “Primary()”” error. I’m unable to reproduce this problem as I’m not sure what’s triggering it.
I’m using a connection string in the following format;
I don’t think this is the issue, as a similar issue I found on stack overflow suggests that it’s due to the way the replica sets are set up in Atlas.
Is this a known issue and is there any documentation on troubleshooting this on atlas?
My issue was due to the original developer not using uWSGI correctly. The solution for me was to add the --lazy-apps option to uWSGI. If you don’t add --lazy-apps, it will interfere with pymongo’s threads (by copying the address space of the parent thread).
You could also try to alter your connection string. Try adding a &replicaSet=yourreplicasetsname option to the end of your connection string. You can also try readPreference=PrimaryPreffered, though this will only work for read operations. Any multiple collection writes would not work with this, at least on Atlas.