Lab - Shard a collection error to import data

Hi,

I can’t upload data because it shows the an error related to the shardIdentity document

Is there something missing??

First question would be whether your sharded cluster has been set up correctly :slight_smile:

If you use the mongo shell to connect to mongos, what does sh.status() report?

It shows an error, the balancer is not running due to read preference. Ive already checked the .conf files on the shards and added: “authorization: enabled” line in the first shard (m103-repl), I restarted however the result is the same.

Thanks

The important part of the error:

Could not find host matching read pref “primary” for set m103-repl.

Seems that one of your replica sets is down. What does the shell show when you connect to m103-repl and run rs.status()?

it shows this

MongoDB Enterprise m103-repl:PRIMARY> rs.status()
{
“set” : “m103-repl”,
“date” : ISODate(“2018-11-03T21:19:33.950Z”),
“myState” : 1,
“term” : NumberLong(3),
“syncingTo” : “”,
“syncSourceHost” : “”,
“syncSourceId” : -1,
“heartbeatIntervalMillis” : NumberLong(2000),
“optimes” : {
“lastCommittedOpTime” : {
“ts” : Timestamp(1541279971, 1),
“t” : NumberLong(3)
},
“readConcernMajorityOpTime” : {
“ts” : Timestamp(1541279971, 1),
“t” : NumberLong(3)
},
“appliedOpTime” : {
“ts” : Timestamp(1541279971, 1),
“t” : NumberLong(3)
},
“durableOpTime” : {
“ts” : Timestamp(1541279971, 1),
“t” : NumberLong(3)
}
},
“members” : [
{
“_id” : 0,
“name” : “192.168.103.100:27001”,
“health” : 1,
“state” : 1,
“stateStr” : “PRIMARY”,
“uptime” : 4059,
“optime” : {
“ts” : Timestamp(1541279971, 1),
“t” : NumberLong(3)
},
“optimeDate” : ISODate(“2018-11-03T21:19:31Z”),
“syncingTo” : “”,
“syncSourceHost” : “”,
“syncSourceId” : -1,
“infoMessage” : “”,
“electionTime” : Timestamp(1541275929, 1),
“electionDate” : ISODate(“2018-11-03T20:12:09Z”),
“configVersion” : 3,
“self” : true,
“lastHeartbeatMessage” : “”
},
{
“_id” : 1,
“name” : “192.168.103.100:27002”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 4049,
“optime” : {
“ts” : Timestamp(1541279971, 1),
“t” : NumberLong(3)
},
“optimeDurable” : {
“ts” : Timestamp(1541279971, 1),
“t” : NumberLong(3)
},
“optimeDate” : ISODate(“2018-11-03T21:19:31Z”),
“optimeDurableDate” : ISODate(“2018-11-03T21:19:31Z”),
“lastHeartbeat” : ISODate(“2018-11-03T21:19:32.932Z”),
“lastHeartbeatRecv” : ISODate(“2018-11-03T21:19:33.467Z”),
“pingMs” : NumberLong(0),
“lastHeartbeatMessage” : “”,
“syncingTo” : “192.168.103.100:27001”,
“syncSourceHost” : “192.168.103.100:27001”,
“syncSourceId” : 0,
“infoMessage” : “”,
“configVersion” : 3
},
{
“_id” : 2,
“name” : “192.168.103.100:27003”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 4040,
“optime” : {
“ts” : Timestamp(1541279971, 1),
“t” : NumberLong(3)
},
“optimeDurable” : {
“ts” : Timestamp(1541279971, 1),
“t” : NumberLong(3)
},
“optimeDate” : ISODate(“2018-11-03T21:19:31Z”),
“optimeDurableDate” : ISODate(“2018-11-03T21:19:31Z”),
“lastHeartbeat” : ISODate(“2018-11-03T21:19:33.065Z”),
“lastHeartbeatRecv” : ISODate(“2018-11-03T21:19:33.444Z”),
“pingMs” : NumberLong(0),
“lastHeartbeatMessage” : “”,
“syncingTo” : “192.168.103.100:27002”,
“syncSourceHost” : “192.168.103.100:27002”,
“syncSourceId” : 1,
“infoMessage” : “”,
“configVersion” : 3
}
],
“ok” : 1
}

It looks similar to the “m103-repl-2”

I have to redo all in order to continue, however it will be nice to know how to fix it.

Ohoh! I’ve learned something :slight_smile:

This thread here -> https://dba.stackexchange.com/questions/135240/mongodb-could-not-find-host-matching-read-preference-mode-primary-for-s

Suggests that we should have also checked the “mongos” log file. Could have been that authentication was failing.