replSetGetStatus

On this page

Definition

replSetGetStatus

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:

db.adminCommand( { replSetGetStatus: 1 } )

Starting in MongoDB 3.4, when running on a secondary member, you can optionally include initialSync: 1 to return initial sync status information:

db.adminCommand( { replSetGetStatus: 1, initialSync: 1 } )

Data provided by this command derives from data included in heartbeats sent to the server by other members of the replica set. Because of the frequency of heartbeats, these data can be several seconds out of date.

The mongo shell provides the rs.status() helper; however, you cannot specify the initialSync: 1 option using the helper.

The mongod instance must have replication enabled and be a member of a replica set for replSetGetStatus to return successfully.

Example

The following example runs the replSetGetStatus command on the admin database of the replica set primary:

db.adminCommand( { replSetGetStatus : 1 } )

The command returns the following output for an example replica set primary:

{
   "set" : "replset",
   "date" : ISODate("2018-12-06T16:57:52.480Z"),
   "myState" : 1,
   "term" : NumberLong(1),
   "syncingTo" : "",
   "syncSourceHost" : "",
   "syncSourceId" : -1,
   "heartbeatIntervalMillis" : NumberLong(2000),
   "optimes" : {
      "lastCommittedOpTime" : {
         "ts" : Timestamp(1544115471, 2),
         "t" : NumberLong(1)
      },
      "readConcernMajorityOpTime" : {
         "ts" : Timestamp(1544115471, 2),
         "t" : NumberLong(1)
      },
      "appliedOpTime" : {
         "ts" : Timestamp(1544115471, 2),
         "t" : NumberLong(1)
      },
      "durableOpTime" : {
         "ts" : Timestamp(1544115471, 2),
         "t" : NumberLong(1)
      }
   },
   "members" : [
      {
         "_id" : 0,
         "name" : "m1.example.net:27017",
         "health" : 1,
         "state" : 1,
         "stateStr" : "PRIMARY",
         "uptime" : 123,
         "optime" : {
            "ts" : Timestamp(1544115471, 2),
            "t" : NumberLong(1)
         },
         "optimeDate" : ISODate("2018-12-06T16:57:51Z"),
         "syncingTo" : "",
         "syncSourceHost" : "",
         "syncSourceId" : -1,
         "infoMessage" : "could not find member to sync from",
         "electionTime" : Timestamp(1544115363, 1),
         "electionDate" : ISODate("2018-12-06T16:56:03Z"),
         "configVersion" : 1,
         "self" : true,
         "lastHeartbeatMessage" : ""
      },
      {
         "_id" : 1,
         "name" : "m2.example.net:27017",
         "health" : 1,
         "state" : 2,
         "stateStr" : "SECONDARY",
         "uptime" : 120,
         "optime" : {
            "ts" : Timestamp(1544115471, 2),
            "t" : NumberLong(1)
         },
         "optimeDurable" : {
            "ts" : Timestamp(1544115471, 2),
            "t" : NumberLong(1)
         },
         "optimeDate" : ISODate("2018-12-06T16:57:51Z"),
         "optimeDurableDate" : ISODate("2018-12-06T16:57:51Z"),
         "lastHeartbeat" : ISODate("2018-12-06T16:57:51.963Z"),
         "lastHeartbeatRecv" : ISODate("2018-12-06T16:57:52.082Z"),
         "pingMs" : NumberLong(0),
         "lastHeartbeatMessage" : "",
         "syncingTo" : "m1.example.net:27017",
         "syncSourceHost" : "m1.example.net:27017",
         "syncSourceId" : 0,
         "infoMessage" : "",
         "configVersion" : 1
      },
      {
         "_id" : 2,
         "name" : "m3.example.net:27017",
         "health" : 1,
         "state" : 2,
         "stateStr" : "SECONDARY",
         "uptime" : 120,
         "optime" : {
            "ts" : Timestamp(1544115471, 2),
            "t" : NumberLong(1)
         },
         "optimeDurable" : {
            "ts" : Timestamp(1544115471, 2),
            "t" : NumberLong(1)
         },
         "optimeDate" : ISODate("2018-12-06T16:57:51Z"),
         "optimeDurableDate" : ISODate("2018-12-06T16:57:51Z"),
         "lastHeartbeat" : ISODate("2018-12-06T16:57:51.963Z"),
         "lastHeartbeatRecv" : ISODate("2018-12-06T16:57:52.082Z"),
         "pingMs" : NumberLong(0),
         "lastHeartbeatMessage" : "",
         "syncingTo" : "m1.example.net:27017",
         "syncSourceHost" : "m1.example.net:27017",
         "syncSourceId" : 0,
         "infoMessage" : "",
         "configVersion" : 1
      }
   ],
   "ok" : 1,
   "operationTime" : Timestamp(1544115471, 2),
   "$clusterTime" : {
      "clusterTime" : Timestamp(1544115471, 2),
      "signature" : {
         "hash" : BinData(0,"aE8X8Wcbyp0Begv7aPnhlkDa1/0="),
         "keyId" : NumberLong("6631924993926103041")
      }
   }
}

The following example runs the replSetGetStatus command on the admin database of the replica set primary. In this example, the optional initialSync: 1 is included in the command (you can omit if you do not want to return the initial sync status):

db.adminCommand( { replSetGetStatus : 1, initialSync: 1 } )

The command returns the following output for an example replica set secondary:

{
   "set" : "replset",
   "date" : ISODate("2018-12-06T17:16:20.037Z"),
   "myState" : 2,
   "term" : NumberLong(1),
   "syncingTo" : "m2.example.net:27017",
   "syncSourceHost" : "m2.example.net:27017",
   "syncSourceId" : 1,
   "heartbeatIntervalMillis" : NumberLong(2000),
   "optimes" : {
      "lastCommittedOpTime" : {
         "ts" : Timestamp(1544116575, 1),
         "t" : NumberLong(1)
      },
      "readConcernMajorityOpTime" : {
         "ts" : Timestamp(1544116575, 1),
         "t" : NumberLong(1)
      },
      "appliedOpTime" : {
         "ts" : Timestamp(1544116575, 1),
         "t" : NumberLong(1)
      },
      "durableOpTime" : {
         "ts" : Timestamp(1544116575, 1),
         "t" : NumberLong(1)
      }
   },
   "initialSyncStatus" : {
      "failedInitialSyncAttempts" : 0,
      "maxFailedInitialSyncAttempts" : 10,
      "initialSyncStart" : ISODate("2018-12-06T17:15:57.546Z"),
      "initialSyncEnd" : ISODate("2018-12-06T17:15:58.221Z"),
      "initialSyncElapsedMillis" : 675,
      "initialSyncAttempts" : [
         {
            "durationMillis" : 439,
            "status" : "OK",
            "syncSource" : "m2.example.net:27017"
         }
      ],
      "fetchedMissingDocs" : 0,
      "appliedOps" : 0,
      "initialSyncOplogStart" : Timestamp(1544116550, 2),
      "initialSyncOplogEnd" : Timestamp(1544116550, 2),
      "databases" : {
         "databasesCloned" : 3,
         "admin" : {
            "collections" : 4,
            "clonedCollections" : 4,
            "start" : ISODate("2018-12-06T17:15:57.783Z"),
            "end" : ISODate("2018-12-06T17:15:58.031Z"),
            "elapsedMillis" : 248,
            "admin.system.roles" : {
               "documentsToCopy" : 1,
               "documentsCopied" : 1,
               "indexes" : 2,
               "fetchedBatches" : 1,
               "start" : ISODate("2018-12-06T17:15:57.784Z"),
               "end" : ISODate("2018-12-06T17:15:57.862Z"),
               "elapsedMillis" : 78
            },
            ...
         },
         ...
         "test" : {
            "collections" : 1,
            "clonedCollections" : 1,
            "start" : ISODate("2018-12-06T17:15:58.155Z"),
            "end" : ISODate("2018-12-06T17:15:58.208Z"),
            "elapsedMillis" : 53,
            "test.foo" : {</