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

Hi,
I am getting the below error while doing " Lab - Shard a Collection"
I am getting this error while adding m103-repl-2 as a shard through mongos
image

I have the below processes running:
image

The error indicates that it can’t find a member with a Primary or PrimaryPreferred read preference, i.e. most likely the Primary node hasn’t been configured for the m103-repl-2 replica set. Log into this replica set and let’s see the outputs of rs.isMaster() and rs.status()

rs.isMaster()

rs.status() 




as you can see m103:27006 is set as PRIMARY

Let’s try sh.add(“m103-repl-2/m103:27006”)

Same error again:

Ok. There’s something wrong with the config; either in mongos or one of the replica set members.

Do two things:

  1. Open the mongos log file, start from the bottom and see what error message it returns
  2. Show a screenshot of the config files for mongos and one of the replica set nodes. Only do this if you can’t figure out the problem from step 1.

Hi @Rounak_65961,

As I can see, you have completed the course successfully. However, if you are still stuck with this issue then please share the content of one of the configuration file in the m103-repl-2.

Thanks,
Shubham Ranjan
Curriculum Support Engineer

Hi,

I am facing same issue.Please find the below screenshot.


rs.status() command
MongoDB Enterprise m103-repl:SECONDARY> rs.status()
{
“set” : “m103-repl”,
“date” : ISODate(“2020-01-08T10:06:44.965Z”),
“myState” : 2,
“term” : NumberLong(10),
“syncingTo” : “192.168.103.100:27001”,
“syncSourceHost” : “192.168.103.100:27001”,
“syncSourceId” : 0,
“heartbeatIntervalMillis” : NumberLong(2000),
“optimes” : {
“lastCommittedOpTime” : {
“ts” : Timestamp(1578478001, 1),
“t” : NumberLong(10)
},
“readConcernMajorityOpTime” : {
“ts” : Timestamp(1578478001, 1),
“t” : NumberLong(10)
},
“appliedOpTime” : {
“ts” : Timestamp(1578478001, 1),
“t” : NumberLong(10)
},
“durableOpTime” : {
“ts” : Timestamp(1578478001, 1),
“t” : NumberLong(10)
}
},
“members” : [
{
“_id” : 0,
“name” : “192.168.103.100:27001”,
“health” : 1,
“state” : 1,
“stateStr” : “PRIMARY”,
“uptime” : 3360,
“optime” : {
“ts” : Timestamp(1578478001, 1),
“t” : NumberLong(10)
},
“optimeDurable” : {
“ts” : Timestamp(1578478001, 1),
“t” : NumberLong(10)
},
“optimeDate” : ISODate(“2020-01-08T10:06:41Z”),
“optimeDurableDate” : ISODate(“2020-01-08T10:06:41Z”),
“lastHeartbeat” : ISODate(“2020-01-08T10:06:43.475Z”),
“lastHeartbeatRecv” : ISODate(“2020-01-08T10:06:44.534Z”),
“pingMs” : NumberLong(0),
“lastHeartbeatMessage” : “”,
“syncingTo” : “”,
“syncSourceHost” : “”,
“syncSourceId” : -1,
“infoMessage” : “”,
“electionTime” : Timestamp(1578471889, 1),
“electionDate” : ISODate(“2020-01-08T08:24:49Z”),
“configVersion” : 5
},
{
“_id” : 1,
“name” : “192.168.103.100:27002”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 3362,
“optime” : {
“ts” : Timestamp(1578478001, 1),
“t” : NumberLong(10)
},
“optimeDate” : ISODate(“2020-01-08T10:06:41Z”),
“syncingTo” : “192.168.103.100:27001”,
“syncSourceHost” : “192.168.103.100:27001”,
“syncSourceId” : 0,
“infoMessage” : “”,
“configVersion” : 5,
“self” : true,
“lastHeartbeatMessage” : “”
},
{
“_id” : 2,
“name” : “m103:27003”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 3360,
“optime” : {
“ts” : Timestamp(1578478001, 1),
“t” : NumberLong(10)
},
“optimeDurable” : {
“ts” : Timestamp(1578478001, 1),
“t” : NumberLong(10)
},
“optimeDate” : ISODate(“2020-01-08T10:06:41Z”),
“optimeDurableDate” : ISODate(“2020-01-08T10:06:41Z”),
“lastHeartbeat” : ISODate(“2020-01-08T10:06:43.426Z”),
“lastHeartbeatRecv” : ISODate(“2020-01-08T10:06:44.417Z”),
“pingMs” : NumberLong(0),
“lastHeartbeatMessage” : “”,
“syncingTo” : “192.168.103.100:27001”,
“syncSourceHost” : “192.168.103.100:27001”,
“syncSourceId” : 0,
“infoMessage” : “”,
“configVersion” : 5
}
],
“ok” : 1,
“operationTime” : Timestamp(1578478001, 1),
“$gleStats” : {
“lastOpTime” : Timestamp(0, 0),
“electionId” : ObjectId(“000000000000000000000000”)
},
“$configServerState” : {
“opTime” : {
“ts” : Timestamp(1578477996, 4),
“t” : NumberLong(2)
}
},
“$clusterTime” : {
“clusterTime” : Timestamp(1578478001, 1),
“signature” : {
“hash” : BinData(0,“IPUQ1TvfkstoH8aZ3jGT65Nq4LE=”),
“keyId” : NumberLong(“6779214403351871514”)
}
}
}
rs.isMaster() command
{
“hosts” : [
“192.168.103.100:27001”,
“192.168.103.100:27002”,
“m103:27003”
],
“setName” : “m103-repl”,
“setVersion” : 5,
“ismaster” : false,
“secondary” : true,
“primary” : “192.168.103.100:27001”,
“me” : “192.168.103.100:27002”,
“lastWrite” : {
“opTime” : {
“ts” : Timestamp(1578478244, 1),
“t” : NumberLong(10)
},
“lastWriteDate” : ISODate(“2020-01-08T10:10:44Z”),
“majorityOpTime” : {
“ts” : Timestamp(1578478244, 1),
“t” : NumberLong(10)
},
“majorityWriteDate” : ISODate(“2020-01-08T10:10:44Z”)
},
“maxBsonObjectSize” : 16777216,
“maxMessageSizeBytes” : 48000000,
“maxWriteBatchSize” : 100000,
“localTime” : ISODate(“2020-01-08T10:10:50.141Z”),
“logicalSessionTimeoutMinutes” : 30,
“minWireVersion” : 0,
“maxWireVersion” : 6,
“readOnly” : false,
“ok” : 1,
“operationTime” : Timestamp(1578478244, 1),
“$gleStats” : {
“lastOpTime” : Timestamp(0, 0),
“electionId” : ObjectId(“000000000000000000000000”)
},
“$configServerState” : {
“opTime” : {
“ts” : Timestamp(1578478245, 1),
“t” : NumberLong(2)
}
},
“$clusterTime” : {
“clusterTime” : Timestamp(1578478246, 1),
“signature” : {
“hash” : BinData(0,“oaXbg+htRnoDgKuHb6i5Qbl/uCc=”),
“keyId” : NumberLong(“6779214403351871514”)
}
}
}

Hi @Siddesh_42092,

The error message says that the mongos cannot find the Primary of the m103-repl-2 replica set. The outputs that you have shared is for m103-repl replica set.

Please make sure that all the nodes for m103-repl-2 is up and running.

In addition to that please make sure that the hostname m103 is getting mapped to the correct IP address i.e. 192.168.103.100 by running this command.

ping m103

Thanks,
Shubham Ranjan
Curriculum Services Engineer

1 Like

Yes I connected to m102-repl-2 replica set
Please find the ping screenshot below


But now I am facing error while sharding the collection.

Collection not sharded - make sure to enable sharding on the ‘m103’ database and
then shard the ‘products’ collection.

Hi @Siddesh_42092,

This is a part of the Lab. You will have to figure out by yourself what could be a good shard key. Refer the lecture videos if you need to revise the concept.

Alternatively, you can also read about this in the doc - Choosing a shard key.

Remember the mongoimport command has --drop parameter, which results in dropping the sharded collection from you database if in case it already exists. That means you will have to repeat the instructions again.

Hope it helps!

Thanks,
Shubham Ranjan
Curriculum Services Engineer