To check replication status, mongodb has rs.status() inbuilt function.
abc:PRIMARY> rs.status function () { return db._adminCommand("replSetGetStatus"); }
rs.status ouput
If secondary is synced and wasn’t created with slaveDelay
option then optime
and optimeDate
of secondary should be equal or close (if there are current operations) to those of primary. In that case stateStr
should be equal to SECONDARY
. So if secondary is synced you should see output similar to this (one member has been removed from output for clarity):
abc:PRIMARY> rs.status() { "set" : "abc", "date" : ISODate("2016-06-22T03:23:58.327Z"), "myState" : 1, "members" : [ { "_id" : 0, "name" : "PC114:27001", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 72635, "optime" : Timestamp(1466563991, 607), "optimeDate" : ISODate("2016-06-22T02:53:11Z"), "electionTime" : Timestamp(1466495099, 1), "electionDate" : ISODate("2016-06-21T07:44:59Z"), "configVersion" : 1, "self" : true }, { "_id" : 1, "name" : "PC114:27002", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 70742, "optime" : Timestamp(1466563991, 607), "optimeDate" : ISODate("2016-06-22T02:53:11Z"), "lastHeartbeat" : ISODate("2016-06-22T03:23:57.854Z"), "lastHeartbeatRecv" : ISODate("2016-06-22T03:23:57.855Z"), "pingMs" : 0, "syncingTo" : "PC114:27001", "configVersion" : 1 }, { "_id" : 2, "name" : "PC114:27003", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 70742, "optime" : Timestamp(1466563991, 607), "optimeDate" : ISODate("2016-06-22T02:53:11Z"), "lastHeartbeat" : ISODate("2016-06-22T03:23:57.854Z"), "lastHeartbeatRecv" : ISODate("2016-06-22T03:23:57.855Z"), "pingMs" : 0, "syncingTo" : "PC114:27001", "configVersion" : 1 } ], "ok" : 1 }