I've one primary host as mongo1.ppshein.net
, secondary host as mongo1.ppshein.net
and arbiter as mongo3.ppshein.net
, and configured MongoDB replica as above shown in AWS EC2. And in each of MongoDB config file, bindIP
is as its host name and App Server host.
To access that MongoDB replica from python, I thought I could be able to use following code-snippet,
>>> from pymongo import MongoClient
>>> db = MongoClient('mongodb://serverA:27017, serverB:27017, serverC:27017/?replicaSet=foo').db_name
But problem is if serverA
is down/unhealthy, I'm not sure whether above code-snippet would be working properly or not. That's why I'm curious to know how to get primary host of MongoDB instead of adding multiple hosts in connection string?