Quantcast
Channel: StackExchange Replication Questions
Viewing all articles
Browse latest Browse all 17268

pymongo MongoClient connect to ReplicaSet

$
0
0

I adopted pymongo's MongoClient class to do connect to a replicaset which has three node, 1 primary 2 secondary. The code snippet as following:

c = MongoClient([secondary1_hostname, secondary2_hostname], replicaSet='rs0')

When check the three mongod's log, I found there is always a connection created to the primary host, but other 2 secondary not received the connection request from client or got connection immediately disconnected. Seems the client first reached one secondary got the primary address then dropped the connection and created long-term connection to primary.

However, when I use MongoReplicaSetClient class, with the follwing code sinppet:

c = MongoReplicaSetClient(secondary1_name, replicaSet='rs0')

There are always 3 connection created to each replica set member, got from the mongod's log file.

So, why the behavior of MongoClient is always only create connection to the primary? I read the manual of PyMongo, but didn't find the answer. Any suggestion is appreciated.


Viewing all articles
Browse latest Browse all 17268

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>