Could not find host matching read preference { mode: \"primary\" } for set m103-repl

Facing issue while Adding new shard to cluster from mongos:
while setting up a sharded cluster:

MongoDB Enterprise mongos> sh.addShard(“m103-repl/192.168.103.100:27012”)
{
“ok” : 0,
“errmsg” : “Could not find host matching read preference { mode: “primary” } for set m103-repl”,
“code” : 133,
“codeName” : “FailedToSatisfyReadPreference”,
“operationTime” : Timestamp(1583742606, 1),
“$clusterTime” : {
“clusterTime” : Timestamp(1583742606, 1),
“signature” : {
“hash” : BinData(0,“0gmTpkhqABua+AxVH5ME0MyovTU=”),
“keyId” : NumberLong(“6801032935999799323”)
}
}
}

Hi @Yeswitha_97458,

Can you please make sure that the m103-repl replica set is up and running while you are trying to add it to the shard ?

Please connect to the m103-repl replica set PRIMARY and share the output of the following command :

rs.status()

~ Shubham

Hi shubham,
output of replica set :
MongoDB Enterprise m103-repl:PRIMARY> rs.status()
{
“set” : “m103-repl”,
“date” : ISODate(“2020-03-10T05:04:09.366Z”),
“myState” : 1,
“term” : NumberLong(6),
“syncingTo” : “”,
“syncSourceHost” : “”,
“syncSourceId” : -1,
“heartbeatIntervalMillis” : NumberLong(2000),
“optimes” : {
“lastCommittedOpTime” : {
“ts” : Timestamp(1583816640, 1),
“t” : NumberLong(6)
},
“readConcernMajorityOpTime” : {
“ts” : Timestamp(1583816640, 1),
“t” : NumberLong(6)
},
“appliedOpTime” : {
“ts” : Timestamp(1583816640, 1),
“t” : NumberLong(6)
},
“durableOpTime” : {
“ts” : Timestamp(1583816640, 1),
“t” : NumberLong(6)
}
},
“members” : [
{
“_id” : 0,
“name” : “192.168.103.100:27001”,
“health” : 1,
“state” : 1,
“stateStr” : “PRIMARY”,
“uptime” : 202,
“optime” : {
“ts” : Timestamp(1583816640, 1),
“t” : NumberLong(6)
},
“optimeDate” : ISODate(“2020-03-10T05:04:00Z”),
“syncingTo” : “”,
“syncSourceHost” : “”,
“syncSourceId” : -1,
“infoMessage” : “”,
“electionTime” : Timestamp(1583816459, 1),
“electionDate” : ISODate(“2020-03-10T05:00:59Z”),
“configVersion” : 3,
“self” : true,
“lastHeartbeatMessage” : “”
},
{
“_id” : 1,
“name” : “192.168.103.100:27002”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 196,
“optime” : {
“ts” : Timestamp(1583816640, 1),
“t” : NumberLong(6)
},
“optimeDurable” : {
“ts” : Timestamp(1583816640, 1),
“t” : NumberLong(6)
},
“optimeDate” : ISODate(“2020-03-10T05:04:00Z”),
“optimeDurableDate” : ISODate(“2020-03-10T05:04:00Z”),
“lastHeartbeat” : ISODate(“2020-03-10T05:04:07.518Z”),
“lastHeartbeatRecv” : ISODate(“2020-03-10T05:04:08.126Z”),
“pingMs” : NumberLong(0),
“lastHeartbeatMessage” : “”,
“syncingTo” : “192.168.103.100:27003”,
“syncSourceHost” : “192.168.103.100:27003”,
“syncSourceId” : 2,
“infoMessage” : “”,
“configVersion” : 3
},
{
“_id” : 2,
“name” : “192.168.103.100:27003”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 191,
“optime” : {
“ts” : Timestamp(1583816640, 1),
“t” : NumberLong(6)
},
“optimeDurable” : {
“ts” : Timestamp(1583816640, 1),
“t” : NumberLong(6)
},
“optimeDate” : ISODate(“2020-03-10T05:04:00Z”),
“optimeDurableDate” : ISODate(“2020-03-10T05:04:00Z”),
“lastHeartbeat” : ISODate(“2020-03-10T05:04:07.518Z”),
“lastHeartbeatRecv” : ISODate(“2020-03-10T05:04:07.610Z”),
“pingMs” : NumberLong(0),
“lastHeartbeatMessage” : “”,
“syncingTo” : “192.168.103.100:27001”,
“syncSourceHost” : “192.168.103.100:27001”,
“syncSourceId” : 0,
“infoMessage” : “”,
“configVersion” : 3
}
],
“ok” : 1,
“operationTime” : Timestamp(1583816640, 1),
“$clusterTime” : {
“clusterTime” : Timestamp(1583816640, 1),
“signature” : {
“hash” : BinData(0,“0Z+72pbAODEbrzz1BwFVUFfxdZo=”),
“keyId” : NumberLong(“6802193358853767170”)
}
}
}
MongoDB Enterprise m103-repl:PRIMARY>

Which lab you are trying to do?
You are trying to addshard with port 27012 but your replica sets running on ports 27001,27002,27003

Please check your lab requirements

Hi @Yeswitha_97458,

As @Ramachandra_37567 mentioned, your m103-repl replica set is running on ports 27001,27002,27003 and you are trying to add a replica set running on port 27012.

~ Shubham

Hi,

Thanks for the input.But,How can I change the replica sets on 27011,27012 and 27013 ports.