Navigation

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-06T18:34:41.288Z"),
   "myState" : 1,
   "term" : NumberLong(1),
   "syncingTo" : "",
   "syncSourceHost" : "",
   "syncSourceId" : -1,
   "heartbeatIntervalMillis" : NumberLong(2000),
   "optimes" : {
      "lastCommittedOpTime" : {
         "ts" : Timestamp(1544121271, 1),
         "t" : NumberLong(1)
      },
      "readConcernMajorityOpTime" : {
         "ts" : Timestamp(1544121271, 1),
         "t" : NumberLong(1)
      },
      "appliedOpTime" : {
         "ts" : Timestamp(1544121271, 1),
         "t" : NumberLong(1)
      },
      "durableOpTime" : {
         "ts" : Timestamp(1544121271, 1),
         "t" : NumberLong(1)
      }
   },
   "lastStableCheckpointTimestamp" : Timestamp(1544121271, 1),
   "members" : [
         {
            "_id" : 0,
            "name" : "m1.example.net:27017",
            "health" : 1,
            "state" : 1,
            "stateStr" : "PRIMARY",
            "uptime" : 85,
            "optime" : {
               "ts" : Timestamp(1544121271, 1),
               "t" : NumberLong(1)
            },
            "optimeDate" : ISODate("2018-12-06T18:34:31Z"),
            "syncingTo" : "",
            "syncSourceHost" : "",
            "syncSourceId" : -1,
            "infoMessage" : "could not find member to sync from",
            "electionTime" : Timestamp(1544121209, 1),
            "electionDate" : ISODate("2018-12-06T18:33:29Z"),
            "configVersion" : 1,
            "self" : true,
            "lastHeartbeatMessage" : ""
         },
         {
            "_id" : 1,
            "name" : "m2.example.net:27017",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 81,
            "optime" : {
               "ts" : Timestamp(1544121271, 1),
               "t" : NumberLong(1)
            },
            "optimeDurable" : {
               "ts" : Timestamp(1544121271, 1),
               "t" : NumberLong(1)
            },
            "optimeDate" : ISODate("2018-12-06T18:34:31Z"),
            "optimeDurableDate" : ISODate("2018-12-06T18:34:31Z"),
            "lastHeartbeat" : ISODate("2018-12-06T18:34:39.866Z"),
            "lastHeartbeatRecv" : ISODate("2018-12-06T18:34:41.118Z"),
            "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" : 12,
            "optime" : {
               "ts" : Timestamp(1544121271, 1),
               "t" : NumberLong(1)
            },
            "optimeDurable" : {
               "ts" : Timestamp(1544121271, 1),
               "t" : NumberLong(1)
            },
            "optimeDate" : ISODate("2018-12-06T18:34:31Z"),
            "optimeDurableDate" : ISODate("2018-12-06T18:34:31Z"),
            "lastHeartbeat" : ISODate("2018-12-06T18:34:40.934Z"),
            "lastHeartbeatRecv" : ISODate("2018-12-06T18:34:40.740Z"),
            "pingMs" : NumberLong(0),
            "lastHeartbeatMessage" : "",
            "syncingTo" : "m2.example.net:27017",
            "syncSourceHost" : "m2.example.net:27017",
            "syncSourceId" : 1,
            "infoMessage" : "",
            "configVersion" : 1
         }
      ],
   "ok" : 1,
   "$clusterTime" : {
      "clusterTime" : Timestamp(1526229410, 1),
      "signature" : {
         "hash" : BinData(0,"WE7yaBuLazOtqwdJxaroLp1Kluo="),
         "keyId" : NumberLong("6554495980643811329")
      }
   },
   "operationTime" : Timestamp(1526229410, 1),
}

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-06T18:39:56.274Z"),
   "myState" : 2,
   "term" : NumberLong(1),
   "syncingTo" : "m2.example.net:27017",
   "syncSourceHost" : "m2.example.net:27017",
   "syncSourceId" : 1,
   "heartbeatIntervalMillis" : NumberLong(2000),
   "optimes" : {
      "lastCommittedOpTime" : {
         "ts" : Timestamp(1544121591, 1),
         "t" : NumberLong(1)
      },
      "readConcernMajorityOpTime" : {
         "ts" : Timestamp(1544121591, 1),
         "t" : NumberLong(1)
      },
      "appliedOpTime" : {
         "ts" : Timestamp(1544121591, 1),
         "t" : NumberLong(1)
      },
      "durableOpTime" : {
         "ts" : Timestamp(1544121591, 1),
         "t" : NumberLong(1)
      }
   },
   "lastStableCheckpointTimestamp" : Timestamp(1544121568, 1),
   "initialSyncStatus" : {
      "failedInitialSyncAttempts" : 0,
      "maxFailedInitialSyncAttempts" : 10,
      "initialSyncStart" : ISODate("2018-12-06T18:34:30.033Z"),
      "initialSyncEnd" : ISODate("2018-12-06T18:34:30.680Z"),
      "initialSyncElapsedMillis" : 647,
      "initialSyncAttempts" : [
         {
            "durationMillis" : 440,
            "status" : "OK",
            "syncSource" : "m2.example.net:27017"
         }
      ],
      "fetchedMissingDocs" : 0,
      "appliedOps" : 0,
      "initialSyncOplogStart" : Timestamp(1544121261, 1),
      "initialSyncOplogEnd" : Timestamp(1544121261, 1),
      "databases" : {
         "databasesCloned" : 3,
         "admin" : {
            "collections" : 4,
            "clonedCollections" : 4,
            "start" : ISODate("2018-12-06T18:34:30.240Z"),
            "end" : ISODate("2018-12-06T18:34:30.564Z"),
            "elapsedMillis" : 324,
            "admin.system.roles" : {
               "documentsToCopy" : 1,
               "documentsCopied" : 1,
               "indexes" : 2,
               "fetchedBatches" : 1,
               "start" : ISODate("2018-12-06T18:34:30.242Z"),
               "end" : ISODate("2018-12-06T18:34:30.345Z"),
               "elapsedMillis" : 103
            },
            ...
         },

         ...
         "test" : {
            "collections" : 1,
            "clonedCollections" : 1,
            "start" : ISODate("2018-12-06T18:34:30.620Z"),
            "end" : ISODate("2018-12-06T18:34:30.676Z"),
            "elapsedMillis" : 56,
            "test.foo" : {
               "documentsToCopy" : 3,
               "documentsCopied" : 3,
               "indexes" : 1,
               "fetchedBatches" : 1,
               "start" : ISODate("2018-12-06T18:34:30.621Z"),
               "end" : ISODate("2018-12-06T18:34:30.676Z"),
               "elapsedMillis" : 55
            }
         }
      }
   },
   "members" : [
      {
         "_id" : 0,
         "name" : "m1.example.net:27017",
         "health" : 1,
         "state" : 1,
         "stateStr" : "PRIMARY",
         "uptime" : 326,
         "optime" : {
            "ts" : Timestamp(1544121591, 1),
            "t" : NumberLong(1)
         },
         "optimeDurable" : {
            "ts" : Timestamp(1544121591, 1),
            "t" : NumberLong(1)
         },
         "optimeDate" : ISODate("2018-12-06T18:39:51Z"),
         "optimeDurableDate" : ISODate("2018-12-06T18:39:51Z"),
         "lastHeartbeat" : ISODate("2018-12-06T18:39:55.066Z"),
         "lastHeartbeatRecv" : ISODate("2018-12-06T18:39:55.209Z"),
         "pingMs" : NumberLong(0),
         "lastHeartbeatMessage" : "",
         "syncingTo" : "",
         "syncSourceHost" : "",
         "syncSourceId" : -1,
         "infoMessage" : "",
         "electionTime" : Timestamp(1544121209, 1),
         "electionDate" : ISODate("2018-12-06T18:33:29Z"),
         "configVersion" : 1
      },
      {
         "_id" : 1,
         "name" : "m2.example.net:27017",
         "health" : 1,
         "state" : 2,
         "stateStr" : "SECONDARY",
         "uptime" : 326,
         "optime" : {
            "ts" : Timestamp(1544121591, 1),
            "t" : NumberLong(1)
         },
         "optimeDurable" : {
            "ts" : Timestamp(1544121591, 1),
            "t" : NumberLong(1)
         },
         "optimeDate" : ISODate("2018-12-06T18:39:51Z"),
         "optimeDurableDate" : ISODate("2018-12-06T18:39:51Z"),
         "lastHeartbeat" : ISODate("2018-12-06T18:39:55.066Z"),
         "lastHeartbeatRecv" : ISODate("2018-12-06T18:39:55.197Z"),
         "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" : 328,
         "optime" : {
            "ts" : Timestamp(1544121591, 1),
            "t" : NumberLong(1)
         },
         "optimeDate" : ISODate("2018-12-06T18:39:51Z"),
         "syncingTo" : "m2.example.net:27017",
         "syncSourceHost" : "m2.example.net:27017",
         "syncSourceId" : 1,
         "infoMessage" : "",
         "configVersion" : 1,
         "self" : true,
         "lastHeartbeatMessage" : ""
      }
   ],
   "ok" : 1,
   "operationTime" : Timestamp(1544121591, 1),
   "$clusterTime" : {
      "clusterTime" : Timestamp(1544121591, 1),
      "signature" : {
         "hash" : BinData(0,"kRCcJowYUXFCTZyCJte3QqrLVa4="),
         "keyId" : NumberLong("6631950102304915457")
      }
   }
}

Output

The replSetGetStatus command returns a document with the following fields:

replSetGetStatus.set

The set value is the name of the replica set, configured in the replSetName setting. This is the same value as _id in rs.conf().

replSetGetStatus.date

An ISODate formatted date and time that reflects the current time according to the server that processed the replSetGetStatus command. Compare this to the values of replSetGetStatus.members[n].lastHeartbeat to find the operational latency between this server and the other members of the replica set.

replSetGetStatus.myState

An integer between 0 and 10 that represents the replica state of the current member.

replSetGetStatus.term

New in version 3.2.

The election count for the replica set, as known to this replica set member. The term is used by the distributed consensus algorithm to ensure correctness.

replSetGetStatus.syncingTo

Deprecated since version 4.0,: 3.6.6, 3.4.16

Starting in MongoDB 4.0 (and 3.6.6, 3.4.16), MongoDB deprecates syncingTo. See replSetGetStatus.syncSourceHost instead.

The syncingTo field holds the hostname of the member from which this instance syncs. If this instance is a primary, returns an empty string "".

replSetGetStatus.syncSourceHost

New in version 4.0,: 3.6.6, 3.4.16

The syncSourceHost field holds the hostname of the member from which this instance syncs.

If this instance is a primary, syncSourceHost is an empty string and the syncSourceId -1.

replSetGetStatus.syncSourceId

New in version 4.0,: 3.6.6, 3.4.16

The syncSourceId field holds the replSetGetStatus.members[n]._id of the member from which this instance syncs.

If this instance is a primary, syncSourceHost is an empty string and the syncSourceId -1.

replSetGetStatus.heartbeatIntervalMillis

New in version 3.2.

The frequency in milliseconds of the heartbeats.

replSetGetStatus.optimes

New in version 3.4.

The optimes field holds a document that contains optimes used to inspect replication progress.

Each optime value is a document that contains:

  • ts, the Timestamp of the operation.
  • t, the term in which the operation was originally generated on the primary.
replSetGetStatus.optimes.lastCommittedOpTime

Information, from the viewpoint of this member, regarding the most recent operation that has been written to a majority of replica set members.

replSetGetStatus.optimes.readConcernMajorityOpTime

Information, from the viewpoint of this member, regarding the most recent operation that can fulfill read concern "majority" queries; i.e. the most recent lastCommittedOpTime that can fulfill "majority" queries. readConcernMajorityOpTime is either less than or equal to lastCommittedOpTime.

replSetGetStatus.optimes.appliedOpTime

Information, from the viewpoint of this member, regarding the most recent operation that has been applied to this member of the replica set.

replSetGetStatus.optimes.durableOpTime

Information,, from the viewpoint of this member, regarding the most recent operation that has been written to the journal of this member of the replica set.

replSetGetStatus.lastStableCheckpointTimestamp

New in version 4.0.

Available for the WiredTiger Storage Engine.

Timestamp at which the current, or a previous, persisted checkpoint was taken. Although lastStableCheckpointTimestamp may lag the most recent persisted checkpoint, the returned timestamp is guaranteed to be persisted in a stable checkpoint to disk.

A null value indicates that no stable checkpoint exists.

replSetGetStatus.initialSyncStatus

New in version 3.4: Available only if the command is run with the initialSync: 1 option on a secondary

A document provides information on the progress and status of initial sync on this secondary.

Note

Some fields that relate to the progress of an on-going initial sync only appear while the initial sync is in progress and do not appear once the initial sync completes.

replSetGetStatus.initialSyncStatus.failedInitialSyncAttempts

New in version 3.4: Available only if the command is run with the initialSync: 1 option on a secondary

The number of times the initial sync failed and had to restart on this secondary.

replSetGetStatus.initialSyncStatus.maxFailedInitialSyncAttempts

New in version 3.4: Available only if the command is run with the initialSync: 1 option on a secondary

The maximum number of times the initial sync can restart on this secondary before the member shuts down.

replSetGetStatus.initialSyncStatus.initialSyncStart

New in version 3.4: Available only if the command is run with the initialSync: 1 option on a secondary

The start timestamp of the initial sync for this secondary.

replSetGetStatus.initialSyncStatus.initialSyncEnd

New in version 3.4: Available only if the command is run with the initialSync: 1 option on a secondary

The end timestamp of the initial sync for this secondary.

replSetGetStatus.initialSyncStatus.initialSyncElapsedMillis

New in version 3.4: Available only if the command is run with the initialSync: 1 option on a secondary

The number of milliseconds between initialSyncStart and initialSyncEnd.

replSetGetStatus.initialSyncStatus.initialSyncAttempts

New in version 3.4: Available only if the command is run with the initialSync: 1 option on a secondary

Array of documents where each document corresponds to a single initial sync attempt. See also failedInitialSyncAttempts.

Each document contains the following information for the initial sync attempt:

{
   "durationMillis" : <duration in milliseconds>,
   "status" : <exit status>,
   "syncSource" : <source node from which this secondary performs initial sync>
}
replSetGetStatus.initialSyncStatus.fetchedMissingDocs

New in version 3.4: Available only if the command is run with the initialSync: 1 option on a secondary

The number of missing (i.e. uncloned) documents that were fetched from the sync source in order to apply to those documents the updates that occurred after the initial sync started.

As part of the initial sync process, the secondary uses the oplog to update its data set to reflect the current state of the replica set.

replSetGetStatus.initialSyncStatus.appliedOps

New in version 3.4: Available only if the command is run with the initialSync: 1 option on a secondary

The number of ops that occurred after the initial sync started and were applied after cloning the databases.

As part of the initial sync process, the secondary uses the oplog to update its data set to reflect the current state of the replica set.

replSetGetStatus.initialSyncStatus.initialSyncOplogStart

New in version 3.4: Available only if the command is run with the initialSync: 1 option on a secondary

The start timestamp of the oplog application stage of the initial sync where the secondary applies changes that occurred after the initial sync start.

As part of the initial sync process, the secondary uses the oplog to update its data set to reflect the current state of the replica set.

replSetGetStatus.initialSyncStatus.initialSyncOplogEnd

New in version 3.4: Available only if the command is run with the initialSync: 1 option on a secondary

The end timestamp of the oplog application stage of the initial sync where the secondary applies changes that occurred after the initial sync start.

As part of the initial sync process, the secondary uses the oplog to update its data set to reflect the current state of the replica set.

replSetGetStatus.initialSyncStatus.databases

New in version 3.4: Available only if the command is run with the initialSync: 1 option on a secondary

Detail on the databases cloned during initial sync.

replSetGetStatus.initialSyncStatus.databases.databasesCloned

New in version 3.4: Available only if the command is run with the initialSync: 1 option on a secondary

Number of databases cloned during initial sync.

replSetGetStatus.initialSyncStatus.databases.<dbname>

New in version 3.4: Available only if the command is run with the initialSync: 1 option on a secondary

For each database, a document that returns information regarding the progress of the cloning of that database.

{
   "collections" : <number of collections to clone in the database>,
   "clonedCollections" : <number of collections cloned to date>,
   "start" : <start date and time for the database clone>,
   "end" : <end date and time for the database clone>,
   "elapsedMillis" : <duration of the database clone>,
   "<db>.<collection>" : {
      "documentsToCopy" : <number of documents to copy>,
      "documentsCopied" : <number of documents copied to date>,
      "indexes" :  <number of indexes>,
      "fetchedBatches" :  <number of batches of documents fetched to date>,
      "start" :  <start date and time for the collection clone>,
      "end" : <end date and time for the collection clone>,
      "elapsedMillis" : <duration of the collection clone>,
   }
}
replSetGetStatus.members

The members field holds an array that contains a document for every member in the replica set.

replSetGetStatus.members[n]._id

The _id field holds the identifier for the member.

replSetGetStatus.members[n].name

The name field holds the name of the server.

replSetGetStatus.members[n].self

The self field is only included in the document for the current mongod instance in the members array. Its value is true.

replSetGetStatus.members[n].health

The health value is only present for the other members of the replica set (i.e. not the member that returns rs.status). This field conveys if the member is up (i.e. 1) or down (i.e. 0).

replSetGetStatus.members[n].state

The value of state is an integer between 0 and 10 that represents the replica state of the member.

replSetGetStatus.members[n].stateStr

A string that describes state.

replSetGetStatus.members[n].uptime

The uptime field holds a value that reflects the number of seconds that this member has been online.

This value does not appear for the member that returns the rs.status() data.

replSetGetStatus.members[n].optime

Information regarding the last operation from the operation log that this member has applied.

Changed in version 3.2.

optime returns a document that contains:

  • ts, the Timestamp of the last operation applied to this member of the replica set from the oplog.
  • t, the term in which the last applied operation was originally generated on the primary.
replSetGetStatus.members[n].optimeDurable

New in version 3.4.

Information regarding the last operation from the operation log that this member has applied to its journal.

optimeDurable returns a document that contains:

  • ts, the Timestamp of the operation.
  • t, the term in which this operation was originally generated on the primary.
replSetGetStatus.members[n].optimeDate

An ISODate formatted date string that reflects the last entry from the oplog that this member applied. If this differs significantly from lastHeartbeat this member is either experiencing “replication lag” or there have not been any new operations since the last update. Compare members.optimeDate between all of the members of the set.

replSetGetStatus.members[n].optimeDurableDate

New in version 3.4.

An ISODate formatted date string that reflects the last entry from the oplog that this member applied to its journal.

replSetGetStatus.members[n].electionTime

For the current primary, information regarding the election Timestamp from the operation log. See Replica Set High Availability for more information about elections.

replSetGetStatus.members[n].electionDate

For the current primary, an ISODate formatted date string that reflects the election date. See Replica Set High Availability for more information about elections.

replSetGetStatus.members[n].self

Indicates which replica set member processed the replSetGetStatus command.

replSetGetStatus.members[n].lastHeartbeat

An ISODate formatted date and time that reflects the last time the server that processed the replSetGetStatus command received a response from a heartbeat that it sent to this member (members[n]). Compare this value to the values of the date and lastHeartBeatRecv fields to track latency between these replica set members.

This value is only available for replica set members other than the server specified by replSetGetStatus.members[n].self.

replSetGetStatus.members[n].lastHeartbeatRecv

An ISODate formatted date and time that reflects the last time the server that processed the replSetGetStatus command received a heartbeat request from this member (members[n]). Compare this value to the values of the date and lastHeartBeat fields to track latency between these replica set members.

This value is only available for replica set members other than the server specified by replSetGetStatus.members[n].self.

replSetGetStatus.members[n].lastHeartbeatMessage

When the last heartbeat included an extra message, the lastHeartbeatMessage contains a string representation of that message.

replSetGetStatus.members[n].pingMs

The pingMs represents the number of milliseconds (ms) that a round-trip packet takes to travel between the remote member and the local instance.

This value does not appear for the member that returns the rs.status() data.

replSetGetStatus.members[n].syncingTo

Deprecated since version 4.0,: 3.6.6, 3.4.16

Starting in MongoDB 4.0 (and 3.6.6, 3.4.16), MongoDB deprecates syncingTo. See replSetGetStatus.members[n].syncSourceHost instead.

The syncingTo field holds the hostname of the member from which this instance is syncing. If the member is a primary, returns an empty string "".

replSetGetStatus.members[n].syncSourceHost

New in version 4.0,: 3.6.6, 3.4.16

The syncSourceHost field holds the hostname of the member from which this instance syncs.

If the replSetGetStatus.members[n] is a primary, syncSourceHost is an empty string and the syncSourceId -1.

replSetGetStatus.members[n].syncSourceId

New in version 4.0,: 3.6.6, 3.4.16

The syncSourceId field holds the replSetGetStatus.members[n]._id value of the syncSourceHost.

If the replSetGetStatus.members[n] is a primary, syncSourceHost is an empty string and the syncSourceId -1.

replSetGetStatus.members[n].configVersion

New in version 3.0.

The configVersion value is the replica set configuration version.

See also Response for details on the ok status field, the operationTime field and the $clusterTime field.