As per MongoDB BOL Here To Check Replica Set Status & display the current state of the replica set and current state of each member, run the rs.status() method in a mongo shell connected to the replica set’s primary.
NOTE: The
rs.status() method is a wrapper that runs the replSetGetStatus
database command.
For Example
Given a replica set with three members running on three separate hosts:
m1.example.net
m2.example.net
m3.example.net
All three use the default port 27017.
Test Connections Between all Members
Test the connection from m1.example.net to the other hosts with the following operation set m1.example.net:
mongo --host m2.example.net --port 27017
mongo --host m3.example.net --port 27017
Test the connection from m2.example.net to the other two hosts with the following operation set from m2.example.net, as in:
mongo --host m1.example.net --port 27017
mongo --host m3.example.net --port 27017
You have now tested the connection between m2.example.net and m1.example.net in both directions.
Test the connection from m3.example.net to the other two hosts with the following operation set from the m3.example.net host, as in:
mongo --host m1.example.net --port 27017
mongo --host m2.example.net --port 27017
If any connection, in any direction fails, check your networking and firewall configuration and reconfigure your environment to allow these connections.
As MongoDB BOL Here The replSetGetStatus
command returns the status of the replica set from the point of view of the server that processed the command. replSetGetStatus
must be run against the admin database
. The command has the following prototype form:
{ replSetGetStatus: 1 }
The following example runs the replSetGetStatus
command on the admin database of the replica set primary
:
db.adminCommand( { replSetGetStatus : 1 } )
Consider the following example output:
{
"set" : "replset",
"date" : ISODate("2016-11-02T20:02:16.543Z"),
"myState" : 1,
"term" : NumberLong(1),
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1478116934, 1),
"t" : NumberLong(1)
},
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1478116934, 1),
"t" : NumberLong(1)
},
"appliedOpTime" : {
"ts" : Timestamp(1478116934, 1),
"t" : NumberLong(1)
},
"durableOpTime" : {
"ts" : Timestamp(1478116934, 1),
"t" : NumberLong(1)
}
},
"members" : [
{
"_id" : 0,
"name" : "m1.example.net:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 269,
"optime" : {
"ts" : Timestamp(1478116934, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2016-11-02T20:02:14Z"),
"infoMessage" : "could not find member to sync from",
"electionTime" : Timestamp(1478116933, 1),
"electionDate" : ISODate("2016-11-02T20:02:13Z"),
"configVersion" : 1,
"self" : true
},
{
"_id" : 1,
"name" : "m2.example.net:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 14,
"optime" : {
"ts" : Timestamp(1478116934, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1478116934, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2016-11-02T20:02:14Z"),
"optimeDurableDate" : ISODate("2016-11-02T20:02:14Z"),
"lastHeartbeat" : ISODate("2016-11-02T20:02:15.618Z"),
"lastHeartbeatRecv" : ISODate("2016-11-02T20:02:14.866Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "m3.example.net:27017",
"configVersion" : 1
},
{
"_id" : 2,
"name" : "m3.example.net:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 14,
"optime" : {
"ts" : Timestamp(1478116934, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1478116934, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2016-11-02T20:02:14Z"),
"optimeDurableDate" : ISODate("2016-11-02T20:02:14Z"),
"lastHeartbeat" : ISODate("2016-11-02T20:02:15.619Z"),
"lastHeartbeatRecv" : ISODate("2016-11-02T20:02:14.787Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "m1.example.net:27018",
"configVersion" : 1
}
],
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1510716515, 1),
"signature" : {
"hash" : BinData(0,"B2ViX7XLzFLS5Fl9XEuFXbwKIM4="),
"keyId" : NumberLong("6488045157173166092")
}
},
"operationTime" : Timestamp(1510716515, 1)
}