Could not find host matching read preference

vagrant@m103:/shared$ cat csrs_1.conf
sharding:
clusterRole: configsvr
replication:
replSetName: m103-csrs
security:
keyFile: /var/mongodb/pki/m103-keyfile
net:
bindIp: localhost,192.168.103.100
port: 26001
systemLog:
destination: file
path: /var/mongodb/db/csrs1/mongod.log
logAppend: true
processManagement:
fork: true
storage:
dbPath: /var/mongodb/db/csrs1

vagrant@m103:/shared$ cat node1.conf
sharding:
clusterRole: shardsvr
storage:
dbPath: /var/mongodb/db/node1
wiredTiger:
engineConfig:
cacheSizeGB: .1
net:
bindIp: 127.0.0.1,m103
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”

vagrant@m103:/shared$ cat mongos.conf
sharding:
configDB: m103-csrs/192.168.103.100:26001,192.168.103.100:26002,192.168.103.100:26003
security:
keyFile: /var/mongodb/pki/m103-keyfile
net:
bindIp: localhost,192.168.103.100
port: 26000
systemLog:
destination: file
path: /var/mongodb/db/mongos.log
logAppend: true
processManagement:
fork: true

vagrant@m103:/shared$ ps -eaf | grep mongo
vagrant 2386 1 4 05:09 ? 00:09:39 mongod -f csrs_1.conf
vagrant 2471 1 4 05:10 ? 00:09:35 mongod -f csrs_2.conf
vagrant 2561 1 4 05:10 ? 00:09:28 mongod -f csrs_3.conf
vagrant 3518 1 0 06:18 ? 00:01:27 mongos -f mongos.conf
vagrant 4116 1 5 06:53 ? 00:07:54 mongod -f node2.conf
vagrant 4206 1 6 06:54 ? 00:08:28 mongod -f node3.conf
vagrant 4626 1 5 07:09 ? 00:06:25 mongod -f node1.conf

Issue could be this line

bindIp: 127.0.0.1,m103

Try to replace hostname with IP

i have already try that and it still doesnt work.
i dont understand from does he take “m103-example” ?

vagrant@m103:/shared$ mongo --port 27001
MongoDB shell version v3.6.12
connecting to: mongodb://127.0.0.1:27001/?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“a9d580f8-842d-4cb8-ae6d-6432d3c02a28”) }
MongoDB server version: 3.6.12
MongoDB Enterprise m103-example:OTHER>

Something wrong in your setup
You should not see m103-example at all.Please check rest of config files.May be you have an old config file from previous class/lab
What is the replicaset name in the config file which has port 27001?
Please check your steps again
Or cleanup everything(kill all mongods,remove all dirs,cfg files) and start from scratch

HI @Tal_38236,

I think this might be the case because there are errors in your configuration file for port 27001.

Here, the port will not have inverted commas else launching mongod for this port will give an error.

I would recommend to remove all the extra configuration files, kill all mongod processes, re check the configuration file for this lab and then re launch the mongod processes.

I hope it helps!!

Let me know, if you still get any issues.

Thanks,
Sonali

Hi
i tried to remove all exttra config file + kill all mongo process
but still the same problem.
you wrote about inverted commas , can you explain what did you mean?
i tried also to run the rs.initiate command but it fails.

MongoDB Enterprise m103-example:OTHER> use admin
switched to db admin
MongoDB Enterprise m103-example:OTHER> 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”

Hi @Tal_38236,

in the configuration file for port 27001, here I see error:

Use IP in place of m103 and remove inverted commas around the port number.

Are you able to launch all mongod processes successfully? Also, check the replSetName for all the nodes

Thanks,
Sonali

Hi

Still the same problem ,
i am using ip instead of m103, i remove the commas from the port
i launched all mongod processes successfully.

this is what i see when connecting to port 27001
MongoDB Enterprise m103-example:OTHER>

Hi @Tal_38236,

I am sorry for your frustration. Lets try to debug it.
Please run the following commands in the same order and share the screenshot.

killall mongod
cat node1.conf
mongod -f node1.conf
mongo --port 27001

Kanika

Hi @Tal_38236,

Thanks for sharing the screenshots. It might be possible that on port 27001, the replica set was initialized using “m103-example” before.
So , please remove this replica set and then try initializing again.

  1. Authenticate against admin database: most likely it is m103-user user with password: m103-pass
    use admin
    db.auth("m103-user","m103-pass")
    
  2. Then run these commands:

    use local
    db.system.replset.drop()

Now, try restarting mongod with same node1.conf file.

Source: Removing a Member from Replica Set or Replica Set as Whole

Let me know how it goes.

Kanika

Hi

i am getting the following error:

MongoDB Enterprise m103-example:OTHER> db.system.replset.drop()
2019-06-03T13:34:36.614+0000 E QUERY [thread1] Error: drop failed: {
“ok” : 0,
“errmsg” : “not authorized on local to execute command { drop: “system.replset”, lsid: { id: UUID(“26341811-cee2-4cef-9b75-561c8bfec1de”) }, $db: “local” }”,
“code” : 13,
“codeName” : “Unauthorized”
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DBCollection.prototype.drop@src/mongo/shell/collection.js:695:1
@(shell):1:1

The error message displays the exact problem here which is that you need to authenticate first. Please make sure you run this before dropping the replica set.

   use admin
   db.auth("m103-user","m103-pass")

Kanika

as you see its already what i did

Hi @Tal_38236,

I am afraid you need to remove all data files and start your replica set again.

To remove all the data files and start completely from scratch .

  • Remove dbPath directory using rm -rf . Example:
   vagrant@m103:~$ rm -rf /var/mongdb/db/node1

Then re-create directory and give permissions again. Let me know.

Kanika

1 Like

thanks , it seems that its work, but why its showing me that i connected to SECONDARY?

Try reconnecting. It will show primary.

Kanika

1 Like

great finally its work
many thanks…

1 Like