I am using 4 nodes for my MongoDB replica set, one as the primary node, two as a secondary node, and one as an arbitrator node. I am using the following connection string in Golang to connect with MongoDB.
opts = options.Client().ApplyURI("mongodb://" + ipPort + "," + secIpPort + "," + sec2IpPort + "/?replicaSet=" + repSetName).SetConnectTimeout(5 * time.Second).SetAuth(serverAuth).SetWriteConcern(writeconcern.New(writeconcern.WMajority()))
Ip used to make connection are, ipPort= 192.168.1.237 secipPort= 192.168.1.239, sec2IpPort= 192.168.1.2
In My replica Set( PRIMARY-SECONDAY-SECONDAY-ARBITER (PSSA) ), look like the following:
“majorityVoteCount” : 3,
“writeMajorityCount” : 3,
“votingMembersCount” : 4,
“writableVotingMembersCount” : 3
I have setted the Default RW Concern as following,
db.adminCommand({ "setDefaultRWConcern" : 1, "defaultWriteConcern" : { "w" : "majority", "j":true, "wtimeout" : 5000 }, writeConcern: { "w" : "majority", "j":true, "wtimeout" : 5000 }, })
Problem:
When the MongoDb service of the first IP(192.168.1.237)
of the connection string is shut down, the secondary IP(192.168.1.239)
becomes primary and performs all the read operations well. But does not perform the write operations.
How can I deal with this problem? If the first IP of the connection string is down, the secondary IP/node should be able to perform both read and write operations.