Replica Set Related

I have created 3 nodes. one primary and 2 secondary.
When I login by using below command every time its logging to Primary only. Even though I have given the Port different for each login.

mongo --host “m103-repl/” -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin”
mongo --host “m103-repl/” -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin”
mongo --host “m103-repl/” -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin”

How can i login to secondary to check if data (which I have updated in Primary) is flowing to secondary ? and being in secondary how can i ensure I have logged in to which node ?


Just run below command:

   mongo --port 27002

MongoDB Enterprise m103-repl:SECONDARY> db.hostInfo()


Please find what i get : don’t find any secondary information.

MongoDB Enterprise m103-repl:SECONDARY> db.hostInfo()
“operationTime” : Timestamp(1558598314, 1),
“ok” : 0,
“errmsg” : “there are no users authenticated”,
“code” : 13,
“codeName” : “Unauthorized”,
“$clusterTime” : {
“clusterTime” : Timestamp(1558598314, 1),
“signature” : {
“hash” : BinData(0,“q2RSSs4EgB2n8F9teOIvVsD/4jU=”),
“keyId” : NumberLong(“6693791734377218050”)

Also, “show dbs” not working

MongoDB Enterprise m103-repl:SECONDARY> show db
2019-05-23T07:58:07.310+0000 E QUERY [thread1] Error: don’t know how to show [db] :

Please suggest.

Is your replica setup complete?
After connecting to primary did you create the user and run rs.initiate()
rs.status() should show one primary and two secondaries

Regarding other error it should be show dbs not show db

You have to authenticate with a user and password to run db.hostinfo().

@Ramachandra_37567, yes, all those steps are completed including the lab validation. But, i was trying to connect to secondary and see but still its showing as primary only from rs.isMaster() output.

mongo --host “m103-repl/” -u “m103-admin” -p “m103-pass” --authenticationDatabase “admin”
Note that here 27002 is for secondary.

Prompt i get as MongoDB Enterprise m103-repl:PRIMARY>

Here is from rs.status() :
“_id” : 1,
“name” : “”,
“health” : 1,
“state” : 2,
“stateStr” : “SECONDARY”,
“uptime” : 22187,
“optime” : {

Yes this is expected behaviour
When you use --host replica_name/IP:port it will connect to you replicaset primary irrespective of whichever port you use

I you want to connect to individual replicas use this
mongo -u m103-admin -p m103-pass --authenticationDatabase admin --port 27001
mongo -u m103-admin -p m103-pass --authenticationDatabase admin --port 27002
mongo -u m103-admin -p m103-pass --authenticationDatabase admin --port 27003