MongoDB Enterprise Cluster0-shard-0:SECONDARY>

Hi,
I am unable to connect to “Cluster0-shard-0: Primary”?
Tried many times as in the connections notes to connect to class cluster but always get “MongoDB Enterprise Cluster0-shard-0:SECONDARY>”?
Hope someone can help.
Thanks
Kelvin

Details as:
MongoDB shell version v4.0.5
MongoDB server version: 3.6.9
WARNING: shell and server versions do not match

MongoDB Enterprise Cluster0-shard-0:SECONDARY>

@Kelvin_35560 Can you provide a couple bits of info to help diagnose.

  1. The command you are using to connect (i.e the full mongo …) that you enter in the shell

  2. Any errors you receive related to the connection command?

  3. The output of “rs.status()” from a node in that cluster/replica set you can connect to.

Thanks,
Mike

Here are some lecture notes that were appended to the Connecting to Your Sandbox Cluster from the Mongo Shell lecture. It addresses your issue.

In this lecture video we end up getting connected to the Primary node of our Sandbox replica set. In case you get connected to a Secondary node, in order to run queries or commands, you will have to run rs.slaveOk() shell command, to list databases, collections and run queries.

hi AkashdeepDhar,
issued rs.slaveOk(), the secondary can connect with class cluster.
Thanks

1 Like

Hi Mike,
The command ran as below in cmd

C:\Users\Asus>
mongo “mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017, cluster0-shard-00-01-jxeqq.mongodb.net:27017, cluster0-shard-00-02-jxeqq.mongodb.net:27017/test? replicaSet=Cluster0-shard-0” --authenticationDatabase admin --ssl --username m001-student --password m001-mongodb-basics

MongoDB shell version v4.0.5

connecting to: mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,%20cluster0-shard-00-01-jxeqq.mongodb.net:27017,%20cluster0-shard-00-02-jxeqq.mongodb.net:27017/test?%20replicaSet=Cluster0-shard-0&authSource=admin&gssapiServiceName=mongodb

Implicit session: session { “id” : UUID(“9c134ec9-9efa-444a-8e12-4fda519b2807”) }
MongoDB server version: 3.6.9
WARNING: shell and server versions do not match
MongoDB Enterprise Cluster0-shard-0:SECONDARY>

Thanks for assist

1 Like

@Kelvin_35560 You are most welcome. :grin:

@Kelvin_35560 rs.slaveOK() just tells a secondary node that it can be read from. What we need to determine is whether there is a primary in your replicas set (or just secondaries). Can you post the output of the “rs.status()” command here? That will show the state of each member of the replica set you’re connecting to.

Thanks!
Mike

1 Like

Hi Mike,
Ran the “rs.status()” the result as below:

MongoDB Enterprise Cluster0-shard-0:SECONDARY> rs.status()

{

“set” : “Cluster0-shard-0”,

“date” : ISODate(“2019-01-21T08:58:34.563Z”),

“myState” : 2,

“term” : NumberLong(43),

“syncingTo” : “cluster0-shard-00-01-jxeqq.mongodb.net:27017”,

“syncSourceHost” : “cluster0-shard-00-01-jxeqq.mongodb.net:27017”,

“syncSourceId” : 1,

“heartbeatIntervalMillis” : NumberLong(2000),

“optimes” : {

“lastCommittedOpTime” : {

“ts” : Timestamp(1548061113, 1),

“t” : NumberLong(43)

},

“readConcernMajorityOpTime” : {

“ts” : Timestamp(1548061113, 1),

“t” : NumberLong(43)

},

“appliedOpTime” : {

“ts” : Timestamp(1548061113, 1),

“t” : NumberLong(43)

},

“durableOpTime” : {

“ts” : Timestamp(1548061113, 1),

“t” : NumberLong(43)

}

},

“members” : [

{

“_id” : 0,

“name” : “cluster0-shard-00-00-jxeqq.mongodb.net:27017”,

“health” : 1,

“state” : 2,

“stateStr” : “SECONDARY”,

“uptime” : 3150507,

“optime” : {

“ts” : Timestamp(1548061113, 1),

“t” : NumberLong(43)

},

“optimeDate” : ISODate(“2019-01-21T08:58:33Z”),

“syncingTo” : “cluster0-shard-00-01-jxeqq.mongodb.net:27017”,

“syncSourceHost” : “cluster0-shard-00-01-jxeqq.mongodb.net:27017”,

“syncSourceId” : 1,

“infoMessage” : “”,

“configVersion” : 4,

“self” : true,

“lastHeartbeatMessage” : “”

},

{

“_id” : 1,

“name” : “cluster0-shard-00-01-jxeqq.mongodb.net:27017”,

“health” : 1,

“state” : 1,

“stateStr” : “PRIMARY”,

“uptime” : 238222,

“optime” : {

“ts” : Timestamp(1548061103, 1),

“t” : NumberLong(43)

},

“optimeDurable” : {

“ts” : Timestamp(1548061103, 1),

“t” : NumberLong(43)

},

“optimeDate” : ISODate(“2019-01-21T08:58:23Z”),

“optimeDurableDate” : ISODate(“2019-01-21T08:58:23Z”),

“lastHeartbeat” : ISODate(“2019-01-21T08:58:33.068Z”),

“lastHeartbeatRecv” : ISODate(“2019-01-21T08:58:34.457Z”),

“pingMs” : NumberLong(0),

“lastHeartbeatMessage” : “”,

“syncingTo” : “”,

“syncSourceHost” : “”,

“syncSourceId” : -1,

“infoMessage” : “”,

“electionTime” : Timestamp(1547810003, 1),

“electionDate” : ISODate(“2019-01-18T11:13:23Z”),

“configVersion” : 4

},

{

“_id” : 2,

“name” : “cluster0-shard-00-02-jxeqq.mongodb.net:27017”,

“health” : 1,

“state” : 2,

“stateStr” : “SECONDARY”,

“uptime” : 251096,

“optime” : {

“ts” : Timestamp(1548061113, 1),

“t” : NumberLong(43)

},

“optimeDurable” : {

“ts” : Timestamp(1548061113, 1),

“t” : NumberLong(43)

},

“optimeDate” : ISODate(“2019-01-21T08:58:33Z”),

“optimeDurableDate” : ISODate(“2019-01-21T08:58:33Z”),

“lastHeartbeat” : ISODate(“2019-01-21T08:58:33.283Z”),

“lastHeartbeatRecv” : ISODate(“2019-01-21T08:58:33.232Z”),

“pingMs” : NumberLong(1),

“lastHeartbeatMessage” : “”,

“syncingTo” : “cluster0-shard-00-01-jxeqq.mongodb.net:27017”,

“syncSourceHost” : “cluster0-shard-00-01-jxeqq.mongodb.net:27017”,

“syncSourceId” : 1,

“infoMessage” : “”,

“configVersion” : 4

}

],

“ok” : 1,

“operationTime” : Timestamp(1548061113, 1),

“$clusterTime” : {

“clusterTime” : Timestamp(1548061113, 1),

“signature” : {

“hash” : BinData(0,“iHgKGyXxrTJvaYe4jyOwVxOXZIU=”),

“keyId” : NumberLong(“6595588990781358081”)

}

}

}

Thanks for your help.