Definition
isMasterDeprecated since version 4.4.2: Use
helloinstead.isMasterreturns a document that describes the role of themongodinstance. If the optional fieldsaslSupportedMechsis specified, the command also returns anarray of SASL mechanismsused to create the specified user's credentials.If the instance is a member of a replica set, then
isMasterreturns a subset of the replica set configuration and status including whether or not the instance is the primary of the replica set.When sent to a
mongodinstance that is not a member of a replica set,isMasterreturns a subset of this information.MongoDB drivers and clients use
isMasterto determine the state of the replica set members and to discover additional members of a replica set.
Syntax
The command takes the following form:
db.runCommand( { isMaster: 1 } )
Starting in MongoDB 4.0, the isMaster command accepts
optional fields saslSupportedMechs: <db.user> to return an
additional field isMaster.saslSupportedMechs in its result
and comment <any> to add a log comment associated with the command.
db.runCommand( { isMaster: 1, saslSupportedMechs: "<db.username>", comment: <any> } )
The db.isMaster() method in the mongo shell
provides a wrapper around isMaster.
Behavior
Client Disconnection
Starting in MongoDB 4.2, if the client that issued isMaster
disconnects before the operation completes, MongoDB marks isMaster
for termination using killOp.
Output
All Instances
The following isMaster fields are common across all
roles:
isMaster.ismasterA boolean value that reports when this node is writable. If
true, then this instance is a primary in a replica set, or amongosinstance, or a standalonemongod.This field will be
falseif the instance is a secondary member of a replica set or if the member is an arbiter of a replica set.
isMaster.maxBsonObjectSizeThe maximum permitted size of a BSON object in bytes for this
mongodprocess. If not provided, clients should assume a max size of "16 * 1024 * 1024".
isMaster.maxMessageSizeBytesThe maximum permitted size of a BSON wire protocol message. The default value is
48000000bytes.
isMaster.maxWriteBatchSizeThe maximum number of write operations permitted in a write batch. If a batch exceeds this limit, the client driver divides the batch into smaller groups each with counts less than or equal to the value of this field.
The value of this limit is
100,000writes.Changed in version 3.6: The limit raises from
1,000to100,000writes. This limit also applies to legacyOP_INSERTmessages.
isMaster.localTimeReturns the local server time in UTC. This value is an ISO date.
isMaster.logicalSessionTimeoutMinutesNew in version 3.6.
The time in minutes that a session remains active after its most recent use. Sessions that have not received a new read/write operation from the client or been refreshed with
refreshSessionswithin this threshold are cleared from the cache. State associated with an expired session may be cleaned up by the server at any time.Only available when
featureCompatibilityVersionis"3.6"or greater. See Backwards Incompatible Features.
isMaster.connectionIdNew in version 4.2.
An identifier for the
mongod/mongosinstance's outgoing connection to the client.
isMaster.minWireVersionThe earliest version of the wire protocol that this
mongodormongosinstance is capable of using to communicate with clients.Clients may use
minWireVersionto help negotiate compatibility with MongoDB.
isMaster.maxWireVersionThe latest version of the wire protocol that this
mongodormongosinstance is capable of using to communicate with clients.Clients may use
maxWireVersionto help negotiate compatibility with MongoDB.
isMaster.readOnlyNew in version 3.4.
A boolean value that, when
true, indicates that themongodormongosis running in read-only mode.
isMaster.compressionNew in version 3.4.
An array listing the compression algorithms used or available for use (i.e. common to both the client and the
mongodormongosinstance) to compress the communication between the client and themongodormongosinstance.The field is only available if compression is used. For example:
If the
mongodis enabled to use both thesnappy,zlibcompressors and a client has specifiedzlib, thecompressionfield would contain:"compression": [ "zlib" ] If the
mongodis enabled to use both thesnappy,zlibcompressors and a client has specifiedzlib,snappy, thecompressionfield would contain:"compression": [ "zlib", "snappy" ] If the
mongodis enabled to use thesnappycompressor and a client has specifiedzlib,snappy, thecompressionfield would contain :"compression": [ "snappy" ] If the
mongodis enabled to use thesnappycompressor and a client has specifiedzlibor the client has specified no compressor, the field is omitted.
That is, if the client does not specify compression or if the client specifies a compressor not enabled for the connected
mongodormongosinstance, the field does not return.
isMaster.saslSupportedMechsAn array of SASL mechanisms used to create the user's credential or credentials. Supported SASL mechanisms are:
GSSAPISCRAM-SHA-256SCRAM-SHA-1
The field is returned only when the command is run with the
saslSupportedMechsfield:db.runCommand( { isMaster: 1, saslSupportedMechs: "<db.username>" } )
Sharded Instances
mongos instances add the following field to the
isMaster response document:
Replica Sets
isMaster contains these fields when returned by a member
of a replica set:
isMaster.hostsAn array of strings in the format of
"[hostname]:[port]"that lists all members of the replica set that are neither hidden, passive, nor arbiters.Drivers use this array and the
isMaster.passivesto determine which members to read from.
isMaster.secondaryA boolean value that, when
true, indicates if themongodis a secondary member of a replica set.
isMaster.passivesAn array of strings in the format of
"[hostname]:[port]"listing all members of the replica set which have amembers[n].priorityof0.This field only appears if there is at least one member with a
members[n].priorityof0.Drivers use this array and the
isMaster.hoststo determine which members to read from.
isMaster.arbitersAn array of strings in the format of
"[hostname]:[port]"listing all members of the replica set that are arbiters.This field only appears if there is at least one arbiter in the replica set.
isMaster.primaryA string in the format of
"[hostname]:[port]"listing the current primary member of the replica set.
isMaster.arbiterOnlyA boolean value that , when
true, indicates that the current instance is an arbiter. ThearbiterOnlyfield is only present, if the instance is an arbiter.
isMaster.passiveA boolean value that, when
true, indicates that the current instance is passive. Thepassivefield is only present for members with amembers[n].priorityof0.
isMaster.hiddenA boolean value that, when
true, indicates that the current instance is hidden. Thehiddenfield is only present for hidden members.
isMaster.tagsA
tagsdocument contains user-defined tag field and value pairs for the replica set member.{ "<tag1>": "<string1>", "<tag2>": "<string2>",... } For read operations, you can specify a tag set in the read preference to direct the operations to replica set member(s) with the specified tag(s).
For write operations, you can create a customize write concern using
settings.getLastErrorModesandsettings.getLastErrorDefaults.
For more information, see Configure Replica Set Tag Sets.
isMaster.meThe
[hostname]:[port]of the member that returnedisMaster.
isMaster.electionIdA unique identifier for each election. Included only in the output of
isMasterfor the primary. Used by clients to determine when elections occur.
isMaster.lastWriteNew in version 3.4.
A document containing optime and date information for the database's most recent write operation.
isMaster.lastWrite.opTimeAn object giving the optime of the last write operation.
isMaster.lastWrite.majorityOpTimeAn object giving the optime of the last write operation readable by
majorityreads.
isMaster.lastWrite.majorityWriteDateA date object containing the time of the last write operation readable by
majorityreads.
For details on the ok status field, the operationTime field,
and the $clusterTime field, see
Command Response.