Lab - Read Concern and Read Preferences

Hi, I shutdown the two secondary nodes with rs.remove(“192.168.103.100:27002”) and
rs.remove(“192.168.103.100:27003”) and the replica set is runing with the primary. I tried to shut down the primary but i Could not, this is the msg.
MongoDB Enterprise m103-repl:PRIMARY> rs.remove(“192.168.103.100:27001”)
{
“ok” : 0,
“errmsg” : “No host described in new configuration 11 for replica set m103-repl maps to this node”,
“code” : 103,
“codeName” : “NewReplicaSetConfigurationIncompatible”,
“operationTime” : Timestamp(1577551335, 1),
“$clusterTime” : {
“clusterTime” : Timestamp(1577551335, 1),
“signature” : {
“hash” : BinData(0,“0EGnF/F6xoSkFMUY6Oqt3i3qefw=”),
“keyId” : NumberLong(“6774884676885544962”)
}
}
}
MongoDB Enterprise m103-repl:PRIMARY>

Then I halt the vagrant and change the mongod-repl-1.conf , to take out the replication:
replSetName: m103-repl . Later I run: mongod -f mongod-repl-1 and mongo --host “192.168.103.100:27001” -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin” . After that, in the database applicationData I can read with all the options using:

db.products.find({“name”:“Come Into The World - CD”}).readPref(“primary”).pretty()
db.products.find({“name”:“Come Into The World - CD”}).readPref(“primaryPreferred”).pretty()
db.products.find({“name”:“Come Into The World - CD”}).readPref(“secondary”).pretty()
db.products.find({“name”:“Come Into The World - CD”}).readPref(“nearest”).pretty()
db.products.find({“name”:“Come Into The World - CD”}).readPref(“secondaryPreferred”).pretty()

Is it normal???. Thank you I do not want to fail the lab.

This: “When two of your nodes are unresponsive, you will not be able to connect to the replica set. You will have to connect to the third node, which should be the only healthy node in the cluster.” for me is not true I could run the replica ser with only one node!!!

You also don’t need to halt vagrant to make changes to the config file. The config file is read once when you run mongod and after that it’s not referenced. Plus, the lab was not expecting you to remove the replSetName option so please put it back in and restart all your nodes using a rolling upgrade.

The lab requirement is to shutdown two nodes using db.shutdownServer()

You don’t need to remove the node. Please add it back.

Shutdown the nodes properly like I explained above and you’ll see the behaviour.

Sorry 007_jb I try to do what you said and the available Node always starts as secundary and I cant see the dbs. I have reachable the node un port 27007, and the othes are reachables:

“_id” : 2,
“name” : “192.168.103.100:27003”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 98,
“optime” : {
“ts” : Timestamp(1577578021, 1),
“t” : NumberLong(9)
},
“optimeDate” : ISODate(“2019-12-29T00:07:01Z”),
“syncingTo” : “”,
“syncSourceHost” : “”,
“syncSourceId” : -1,
“infoMessage” : “”,
“configVersion” : 17,
“self” : true,
“lastHeartbeatMessage” : “”

Again thak you very much!!!

Let’s see a screenshot of rs.status()
And also a screenshot of your mongo command.

Or everything is fine now?

Hi 007_jb, unfortunatly I coud not fix my problem:
Here you are the rs.status and the mongo:
MongoDB Enterprise m103-repl:SECONDARY> rs.status()
{
“set” : “m103-repl”,
“date” : ISODate(“2019-12-29T18:16:16.566Z”),
“myState” : 2,
“term” : NumberLong(10),
“syncingTo” : “”,
“syncSourceHost” : “”,
“syncSourceId” : -1,
“heartbeatIntervalMillis” : NumberLong(2000),
“optimes” : {
“lastCommittedOpTime” : {
“ts” : Timestamp(0, 0),
“t” : NumberLong(-1)
},
“appliedOpTime” : {
“ts” : Timestamp(1577578021, 1),
“t” : NumberLong(9)
},
“durableOpTime” : {
“ts” : Timestamp(1577578021, 1),
“t” : NumberLong(9)
}
},
“members” : [
{
“_id” : 0,
“name” : “192.168.103.100:27001”,
“health” : 0,
“state” : 8,
“stateStr” : “(not reachable/healthy)”,
“uptime” : 0,
“optime” : {
“ts” : Timestamp(0, 0),
“t” : NumberLong(-1)
},
“optimeDurable” : {
“ts” : Timestamp(0, 0),
“t” : NumberLong(-1)
},
“optimeDate” : ISODate(“1970-01-01T00:00:00Z”),
“optimeDurableDate” : ISODate(“1970-01-01T00:00:00Z”),
“lastHeartbeat” : ISODate(“2019-12-29T18:16:16.238Z”),
“lastHeartbeatRecv” : ISODate(“1970-01-01T00:00:00Z”),
“pingMs” : NumberLong(0),
“lastHeartbeatMessage” : “Connection refused”,
“syncingTo” : “”,
“syncSourceHost” : “”,
“syncSourceId” : -1,
“infoMessage” : “”,
“configVersion” : -1
},
{
“_id” : 1,
“name” : “192.168.103.100:27002”,
“health” : 0,
“state” : 8,
“stateStr” : “(not reachable/healthy)”,
“uptime” : 0,
“optime” : {
“ts” : Timestamp(0, 0),
“t” : NumberLong(-1)
},
“optimeDurable” : {
“ts” : Timestamp(0, 0),
“t” : NumberLong(-1)
},
“optimeDate” : ISODate(“1970-01-01T00:00:00Z”),
“optimeDurableDate” : ISODate(“1970-01-01T00:00:00Z”),
“lastHeartbeat” : ISODate(“2019-12-29T18:16:16.241Z”),
“lastHeartbeatRecv” : ISODate(“1970-01-01T00:00:00Z”),
“pingMs” : NumberLong(0),
“lastHeartbeatMessage” : “Connection refused”,
“syncingTo” : “”,
“syncSourceHost” : “”,
“syncSourceId” : -1,
“infoMessage” : “”,
“configVersion” : -1
},
{
“_id” : 2,
“name” : “192.168.103.100:27003”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 91,
“optime” : {
“ts” : Timestamp(1577578021, 1),
“t” : NumberLong(9)
},
“optimeDate” : ISODate(“2019-12-29T00:07:01Z”),
“syncingTo” : “”,
“syncSourceHost” : “”,
“syncSourceId” : -1,
“infoMessage” : “”,
“configVersion” : 17,
“self” : true,
“lastHeartbeatMessage” : “”
}
],
“ok” : 1,
“operationTime” : Timestamp(1577578021, 1),
“$clusterTime” : {
“clusterTime” : Timestamp(1577578021, 1),
“signature” : {
“hash” : BinData(0,“YcifDnV5jlDTpnXu3FYM/reC3JU=”),
“keyId” : NumberLong(“6774884676885544962”)
}
}
}

mongo --host “192.168.103.100:27003” -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin”

Here you are my mongod-repl-3.conf:

storage:
dbPath: /var/mongodb/db/3
net:
bindIp: 192.168.103.100,localhost
port: 27003
security:
authorization: enabled
keyFile: /var/mongodb/pki/m103-keyfile
systemLog:
destination: file
path: /var/mongodb/db/mongod3.log
logAppend: true
processManagement:
fork: true
replication:
replSetName: m103-repl

Hi 007_jb:
In the end I have been able to do it with the following commands:
connSecondary = new Mongo(“localhost:27003”)
connSecondary.setSlaveOk()

Is this correct??
Thank you very very very much for your help!!!

Hey @Fernando_Elizaga_32387, almost there. But instead of setSlaveOk(), you need to pass the correct readPreference that will enable you read data from the remaining SECONDARY node. Using the driver, test out all the readPreferences and see which of them allows you to read data from any your collections.

I do not know how to do this 007. I used:

db.products.find({“name”:“Come Into The World - CD”}).readPref(“secondaryPreferred”).pretty()

But it do not work with out setSlaveok().

I dedicated a lot of time trying.
Could you help me with this readPref??? Thank yo again

You are on the right track. It works for me via the mongo shell:

Let’s see a screenshot of what you did. I would like to see how you logged in, the readPref command you ran and the error message all on one screenshot. Also, don’t use Pymongo, just use the mongo shell for now.

Hi @Fernando_Elizaga_32387,

Please ensure the following and you should be fine :

  1. In post #7, connect to the node which is in the Secondary state.

  2. Make sure you are connected to the applicationData database.

    use applicationData

  3. [Your Query]

Hope it helps!

Please feel free to get back to us if you have any other issue.

Thanks,
Shubham Ranjan
Curriculum Support Engineer