Could not find host matching read preference

Hi

Can anyone help please?

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

i have to say that its very disheartening, i am spending days to solve that
and it happens in almost all labs.
it doesnt work as writen in the instructions.

I have already responded to you on another thread
Yes you will face this type of issues due to hostname/IP resolution,aliases not working in vagrant
Please check this link

sh.addShard() errmsg” Could not find host matching read preference…”

Hi

sh.addShard(“m103-repl/192.168.103.100:27001”)

where do i need to change the IP/alias ?

I have mentioned it was a mistake in config file
To clear your doubt
Below line
net:
bindIp: m103,localhost
port: 27001

changed to
net:
bindIp: 192.168.103.100,localhost
port: 27001

Hope it is clear now
In your case it could be some other issue but check your /etc/hosts

Hi

its already like that in node1.conf file

sharding:
clusterRole: shardsvr
storage:
dbPath: /var/mongodb/db/node1
wiredTiger:
engineConfig:
cacheSizeGB: .1
net:
bindIp: 192.168.103.100,localhost
port: 27001
security:
authorization: enabled
keyFile: /var/mongodb/pki/m103-keyfile
systemLog:
destination: file
path: /var/mongodb/db/node1/mongod.log
logAppend: true
processManagement:
fork: true
replication:
replSetName: m103-repl

Hi Tal_38236,

Can you please check if you can ping the IP from inside your vagrant machine?

Please run below command:

 vagrant@m103:~$ ip addr show

Share the output here. Also, if nothing works, try re-provision vagrant again. Command to provision vagrant:

    m103-vagrant-env:~$ vagrant provision

Also, I will recommend please carry on all Labs in the same sequence as they are in the course. Else it can mess up all the configurations.

Kanika

ping 192.168.103.100
PING 192.168.103.100 (192.168.103.100) 56(84) bytes of data.
64 bytes from 192.168.103.100: icmp_seq=1 ttl=64 time=0.037 ms
64 bytes from 192.168.103.100: icmp_seq=2 ttl=64 time=0.132 ms
64 bytes from 192.168.103.100: icmp_seq=3 ttl=64 time=0.125 ms
64 bytes from 192.168.103.100: icmp_seq=4 ttl=64 time=0.111 ms
64 bytes from 192.168.103.100: icmp_seq=5 ttl=64 time=0.102 ms
64 bytes from 192.168.103.100: icmp_seq=6 ttl=64 time=0.118 ms
64 bytes from 192.168.103.100: icmp_seq=7 ttl=64 time=0.126 ms
64 bytes from 192.168.103.100: icmp_seq=8 ttl=64 time=0.183 ms
64 bytes from 192.168.103.100: icmp_seq=9 ttl=64 time=0.209 ms
64 bytes from 192.168.103.100: icmp_seq=10 ttl=64 time=0.113 ms
64 bytes from 192.168.103.100: icmp_seq=11 ttl=64 time=0.101 ms
64 bytes from 192.168.103.100: icmp_seq=12 ttl=64 time=0.117 ms
^C
— 192.168.103.100 ping statistics —
12 packets transmitted, 12 received, 0% packet loss, time 11073ms
rtt min/avg/max/mdev = 0.037/0.122/0.209/0.042 ms

i tried vagrant provision but still the same error.

Hi @Tal_38236,

It seems like a lot of confusion. Please share the following details:

  • Which lab you are currently working on?
  • What is the error and on which command? I can see your first comment, but there is already a solution provided in this thread:
  • Please share replica set status for m103-repl replica set.

There might be few other things you can check:

  • You cannot contact the replica set, because there is no primary.
  • There is no primary because 2/3 replicas are down.
  • The last remaining host is and stays a secondary.
  • To connect to a secondary you have to adjust your connection string.

It’s no longer “RS/host1:port1,host2:port2,host3:port3”, but “host1:port1”.

Kanika

Hi

Regarding your lab question i am sorry but i dont realy remember and the course has finished and i cant check.
The command “sh.addShard(“m103-repl/192.168.103.100:27001”)”
The error:
" “ok” : 0,
“errmsg” : “Could not find host matching read preference { mode: “primary” } for set m103-repl”,
“code” : 133,
“codeName” : “FailedToSatisfyReadPreference”,
“operationTime” : Timestamp(1556716931, 3),
“$clusterTime” : {
“clusterTime” : Timestamp(1556716931, 3),
“signature” : {
“hash” : BinData(0,“V7eydmxitHWOG1bmjJhvbofVxbE=”),
“keyId” : NumberLong(“6684910515103203355”)
}
}
}"

Regarding the replica set status - can you remind me how to check ? i ran the command in order to login but i dont understand why i am seeing m103-example

mongo --port 27001 -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin”
MongoDB Enterprise m103-example:OTHER>

Hi @Tal_38236,

Let’s reconnect once you start the May session of M103 as we need the information I have requested in order to better understand the issues you face.

Kanika

i can give you all information you want.

How can it be possible that it shows me replica set name “m103-example” when doing login?

mongo --port 27001 -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin”
MongoDB Enterprise m103-example:OTHER>

My be mix up of config files or you are trying to connect cluster from previous lab
Also your prompt shows OTHER> which is not correct.After rs.initiate() it should change
It should should show PRIMARY

Hi

i dont think i mix up with the config files.
i ran the command again , see the results
rs.initiate()
{
“info2” : “no configuration specified. Using a default configuration for the set”,
“me” : “192.168.103.100:27001”,
“info” : “try querying local.system.replset to see current configuration”,
“ok” : 0,
“errmsg” : “already initialized”,
“code” : 23,
“codeName” : “AlreadyInitialized”

also see the mongod proccesses that up

$ ps -eaf | grep mong
vagrant 2392 1 1 00:02 ? 00:07:06 mongod -f node3.conf
vagrant 2575 1 2 00:19 ? 00:18:25 mongod -f csrs_1.conf
vagrant 2662 1 2 00:19 ? 00:16:46 mongod -f csrs_2.conf
vagrant 2812 1 2 00:20 ? 00:16:53 mongod -f csrs_3.conf
vagrant 2909 1 0 00:20 ? 00:03:08 mongos -f mongos.conf
vagrant 2966 1 1 00:22 ? 00:11:26 mongod -f node2.conf
vagrant 5195 1 1 03:35 ? 00:07:58 mongod -f node1.conf

if you need the content of specific file please let me know.
Thanks

Hi Tal_38236

I strongly suggest you review your config files again
Are you able to connect to individual hosts in replicaset?
Are you able to connect to replicasets?
Are you able to connect to mongos?
Please check rs.status(),rs.isMaster(),rs.conf()
mongo --host “m103-repl-2/192.168.103.100:27004” -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin” -->connects to first replicaset
mongo --host “m103-repl/192.168.103.100:27001” -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin” —>connects to second replica set

mongo --port 26000 -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin”
–> connects to mongos

If nothing works remove everything and start from scratch

Hi

The only sucessfull conection is to mongos
for the others i am getting
2019-05-06T10:56:08.772+0000 W NETWORK [thread1] Unable to reach primary for set m103-repl-2
2019-05-06T10:56:09.274+0000 W NETWORK [thread1] Failed to connect to 192.168.103.100:27004, in(checking socket for error after poll), reason: Connection refused

2019-05-06T10:59:25.059+0000 W NETWORK [thread1] Failed to connect to 192.168.103.100:27011, in(checking socket for error after poll), reason: Connection refused
2019-05-06T10:59:25.060+0000 W NETWORK [thread1] Unable to reach primary for set m103-repl

i dont understand why the error shows 27011 port although i am trying to connect to port 27001

Hello

Chapter 3: Sharding

Lab - Configure a Sharded Cluster

can anyone help
its the second time id that lab and still
the same problems.
i tried to run the command
mongo --host “m103-repl/192.168.103.100:27001” -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin”
and i get those errors

"
MongoDB shell version v3.6.12
connecting to: mongodb://192.168.103.100:27001/?authSource=admin&gssapiServiceName=mongodb&replicaSet=m103-repl
2019-06-02T06:24:08.591+0000 I NETWORK [thread1] Starting new replica set monitor for m103-repl/192.168.103.100:27001
2019-06-02T06:24:08.595+0000 I NETWORK [thread1] Successfully connected to 192.168.103.100:27001 (1 connections now open to 192.168.103.100:27001 with a 5 second timeout)
2019-06-02T06:24:08.596+0000 W NETWORK [thread1] Failed to connect to 192.168.103.100:27011, in(checking socket for error after poll), reason: Connection refused
2019-06-02T06:24:08.599+0000 W NETWORK [thread1] Unable to reach primary for set m103-repl
2019-06-02T06:24:08.600+0000 I NETWORK [thread1] Cannot reach any nodes for set m103-repl. Please check network connectivity and the status of the set. This has happened for 1 checks in a row.
2019-06-02T06:24:09.109+0000 W NETWORK [thread1] Failed to connect to 192.168.103.100:27011, in(checking socket for error after poll), reason: Connection refused
2019-06-02T06:24:09.111+0000 W NETWORK [thread1] Unable to reach primary for set m103-repl
2019-06-02T06:24:09.118+0000 I NETWORK [thread1] Cannot reach any nodes for set m103-repl. Please check network connectivity and the status of the set. This has happened for 2 checks in a row."

Are your mongods up and running?
3 replicas,3 config and one mongos
Please paste contents of one replica,one config and mongos config files