Error while connecting to Entire replica set:

Hi, can someone please help with this issue.
the error I am getting at -while connecting to Entire replica set:

Following are the steps I followed

created all three config files
created all three folders
started all the mongod Processes
Connected to node1:
Initiated the replica set
created the use - m103-admin
Exited out of the Mongo shell

–Getting error at this point

vagrant@m103:~$ mongo --host “m103-example/192.168.103.100:27011” -u “m103-admin”
-p “m103-pass” --authenticatioMongoDB shell version v3.6.17

Enter password:
Entered the password -m103-pass
Getting the following error

connecting to: mongodb://192.168.103.100:27011/?gssapiServiceName=mongodb&replicaSet=m103-example
2020-02-29T16:24:23.328+0000 I NETWORK [thread1] Starting new replica set monitor for m103-example/192.168.103.100:27011
2020-02-29T16:24:23.331+0000 I NETWORK [thread1] Successfully connected to 192.168.103.100:27011 (1 connections now open to 192.168.103.100:27011 with a 5 second timeout)
2020-02-29T16:24:23.371+0000 I NETWORK [thread1] Marking host 192.168.103.100:27011 as failed :: caused by :: Location40659: can’t connect to new replica set master [192.168.103.100:27011], err: AuthenticationFailed: Authentication failed.
2020-02-29T16:24:23.380+0000 I NETWORK [thread1] Marking host 192.168.103.100:27011 as failed :: caused by :: Location40659: can’t connect to new replica set master [192.168.103.100:27011], err: AuthenticationFailed: Authentication failed.
2020-02-29T16:24:23.918+0000 I NETWORK [thread1] Marking host 192.168.103.100:27011 as failed :: caused by :: Location40659: can’t connect to new replica set master [192.168.103.100:27011], err: AuthenticationFailed: Authentication failed.
2020-02-29T16:24:24.460+0000 I NETWORK [thread1] Marking host 192.168.103.100:27011 as failed :: caused by :: Location40659: can’t connect to new replica set master [192.168.103.100:27011], err: AuthenticationFailed: Authentication failed.
2020-02-29T16:24:24.465+0000 E QUERY [thread1] Error: can’t authenticate against replica set node 192.168.103.100:27011: can’t connect to new replica set master [192.168.103.100:27011], err: AuthenticationFailed: Authentication failed. :
connect@src/mongo/shell/mongo.js:263:13
@(connect):1:6
exception: connect failed
vagrant@m103:~$

If you are doing Lab - Initiate a Replica Set Locally, please be aware that the requested replica set name is not

The name above was used in the video.

The output of the following commands will help to investigate further.

ps -aef | grep [m]ongo
ss -tlnmp

Thanks, I am working on the video example.
As per your instructions, i ran the following commands

vagrant@m103:~$ ps -aef | grep [m]ongo

vagrant 12366 1 3 15:59 ? 00:04:01 mongod -f node1.conf
vagrant 12409 1 1 16:09 ? 00:01:54 mongod -f node2.conf
vagrant 12439 1 1 16:09 ? 00:01:53 mongod -f node3.conf

vagrant@m103:~ ss -tlnmp State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:111 *:* skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0) LISTEN 0 128 *:22 *:* skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0) LISTEN 0 128 *:46689 *:* skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0) LISTEN 0 128 127.0.0.1:27011 *:* users:(("mongod",12366,13)) skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0) LISTEN 0 128 192.168.103.100:27011 *:* users:(("mongod",12366,12)) skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0) LISTEN 0 128 127.0.0.1:27012 *:* users:(("mongod",12409,13)) skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0) LISTEN 0 128 192.168.103.100:27012 *:* users:(("mongod",12409,12)) skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0) LISTEN 0 128 127.0.0.1:27013 *:* users:(("mongod",12439,13)) skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0) LISTEN 0 128 192.168.103.100:27013 *:* users:(("mongod",12439,12)) skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0) LISTEN 0 128 :::51756 :::* skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0) LISTEN 0 128 :::111 :::* skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0) LISTEN 0 128 :::22 :::* skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0) vagrant@m103:~

Your initial post was incomplete. Do any of these connect?

mongo --host m103-example/192.168.103.100:27011,192.168.103.100:27012,192.168.103.100:27013 -u m103-admin -p m103-pass --authenticationDatabase admin

Or

mongo --host m103-example/192.168.103.100:27011,192.168.103.100:27012,192.168.103.100:27013 -u m103-admin -p m103-pass --authenticationDatabase test

1 Like

Thanks for your response

I am working on a video example Chapter 2: Replication Setting Up a Replica Set.

when you look at the steps

mongod -f node1.conf
mongod -f node2.conf
mongod -f node3.conf

vagrant@m103:~$ mongo --port 27011

MongoDB shell version v3.6.17
connecting to: mongodb://127.0.0.1:27011/?gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“05f848e4-b389-4e13-b2e0-bd7d109f9c03”) }
MongoDB server version: 3.6.17

MongoDB Enterprise m103-example:PRIMARY> rs.initiate()
{
“operationTime” : Timestamp(1583013088, 1),
“ok” : 0,
“errmsg” : “there are no users authenticated”,
“code” : 13,
“codeName” : “Unauthorized”,
“$clusterTime” : {
“clusterTime” : Timestamp(1583013088, 1),
“signature” : {
“hash” : BinData(0,“TgVOX3GuXjHcHVSGaar2yh5AeT4=”),
“keyId” : NumberLong(“6798890571952816129”)
}
}
}

MongoDB Enterprise m103-example:PRIMARY> use admin
switched to db admin
db.cMongoDB Enterprise m103-example:PRIMAdb.createUser({
… user: “m103-admin”,
… pwd: “m103-pass”,
… roles: [
… {role: “root”, db: “admin”}
… ]
… })
2020-02-29T21:53:10.502+0000 E QUERY [thread1] Error: couldn’t add user: there are no users authenticated :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1437:15
@(shell):1:1

MongoDB Enterprise m103-example:PRIMARY> exit
bye

vagrant@m103:~$ mongo --host “m103-example/192.168.103.100:27011” -u “m103-admin”
-p “m103-pass” --authenticatioMongoDB shell version v3.6.17

Enter password:m103-pass

connecting to: mongodb://192.168.103.100:27011/?gssapiServiceName=mongodb&replicaSet=m103-example
2020-02-29T21:54:39.444+0000 I NETWORK [thread1] Starting new replica set monitor for m103-example/192.168.103.100:27011
2020-02-29T21:54:39.446+0000 I NETWORK [thread1] Successfully connected to 192.168.103.100:27011 (1 connections now open to 192.168.103.100:27011 with a 5 second timeout)2020-02-29T21:54:39.597+0000 I NETWORK [thread1] Marking host 192.168.103.100:27011 as failed :: caused by :: Location40659: can’t connect to new replica set master [192.168.103.100:27011], err: AuthenticationFailed: Authentication failed.
2020-02-29T21:54:39.615+0000 I NETWORK [thread1] Marking host 192.168.103.100:27011 as failed :: caused by :: Location40659: can’t connect to new replica set master [192.168.103.100:27011], err: AuthenticationFailed: Authentication failed.
2020-02-29T21:54:40.149+0000 I NETWORK [thread1] Marking host 192.168.103.100:27011 as failed :: caused by :: Location40659: can’t connect to new replica set master [192.168.103.100:27011], err: AuthenticationFailed: Authentication failed.
2020-02-29T21:54:40.666+0000 I NETWORK [thread1] Marking host 192.168.103.100:27011 as failed :: caused by :: Location40659: can’t connect to new replica set master [192.168.103.100:27011], err: AuthenticationFailed: Authentication failed.
2020-02-29T21:54:40.667+0000 E QUERY [thread1] Error: can’t authenticate against replica set node 192.168.103.100:27011: can’t connect to new replica set master [192.168.103.100:27011], err: AuthenticationFailed: Authentication failed. :
connect@src/mongo/shell/mongo.js:263:13
@(connect):1:6
exception: connect failed
vagrant@m103:~$

From

it looks like you have a new line just before the -p option. Looks like a bad cut-n-paste. Try just copying from your mongo --host … to … -u "m103-admin" and then complete manually typing -p “m103-pass” ….

1 Like

Thank you so much for your guidance, my issue is resolved now.
when i ran the whole command in one line it ran successfully.

Closing this thread as the issue has been resolved.