Hello. Right now I’m experiencing a weird issue where I can’t connect to a secondary from my local laptop but can from a remote server that holds the mongo replica set.
This is the code I’m using. Right now, no matter what server I specify, it’ll always connect to the primary. But if I run the same thing on the remote server that holds the mongo replica set, then it’ll let me connect to the secondary. I don’t think this is a firewall issue since it doesn’t give any error or indication that the connection failed to the secondary. It just automatically connects to the primary instead.
In this configuration, write operations will be sent to the primary and read operations will be sent to the secondaries.
Note that MongoClient will connect to the entire replica set by default (so that it will be more highly available) even if you only provide a single server.
Is there a way to force it to connect only to the secondary I specify within the connection string for read/write operations? I’m trying to do a compaction/write operations against a specific secondary in the replica set.