isMaster

Definition

  • isMaster
  • isMaster returns a document that describes the role ofthe mongod instance. If the optional fieldsaslSupportedMechs is specified, the command also returns anarray of SASL mechanisms usedto create the specified user’s credentials.

If the instance is a member of areplica set, then isMaster returns a subset of thereplica set configuration and status including whether or not theinstance is the primary of the replica set.

When sent to a mongod instance that is not a member of areplica set, isMaster returns a subset of thisinformation.

MongoDB drivers and clients useisMaster to determine the state of the replica setmembers and to discover additional members of a replicaset.

Syntax

The command takes the following form:

  1. db.runCommand( { isMaster: 1 } )

Starting in MongoDB 4.0, the isMaster command accepts anoptional field saslSupportedMechs: <db.user> to return anadditional field isMaster.saslSupportedMechs in its result.

  1. db.runCommand( { isMaster: 1, saslSupportedMechs: "<db.username>" } )

The db.isMaster() method in the mongo shellprovides a wrapper around isMaster.

Behavior

Client Disconnection

Starting in MongoDB 4.2, if the client that issued the isMasterdisconnects before the operation completes, MongoDB marksthe isMaster for termination (i.e. killOp on theoperation).

Output

All Instances

The following isMaster fields are common across allroles:

  • isMaster.ismaster
  • A boolean value that reports when this node is writable. Iftrue, then this instance is a primary in areplica set, or a mongos instance, or a standalonemongod.

This field will be false if the instance is asecondary member of a replica set or if the member is anarbiter of a replica set.

  • isMaster.maxBsonObjectSize
  • The maximum permitted size of a BSON object in bytes forthis mongod process. If not provided, clients shouldassume a max size of “16 1024 1024”.
  • isMaster.maxMessageSizeBytes
  • The maximum permitted size of a BSON wire protocol message.The default value is 48000000 bytes.
  • isMaster.maxWriteBatchSize
  • The maximum number of write operations permitted in a write batch.If a batch exceeds thislimit, the clientdriver divides the batch into smaller groups each with counts lessthan or equal to the value of this field.

The value of this limit is 100,000 writes.

Changed in version 3.6: The limit raises from 1,000 to 100,000 writes. This limitalso applies to legacy OP_INSERT messages.

  • isMaster.localTime
  • Returns the local server time in UTC. This value is anISO date.
  • isMaster.logicalSessionTimeoutMinutes

New in version 3.6.

The time in minutes that a session remains activeafter its most recent use. Sessions that have not received a newread/write operation from the client or been refreshed withrefreshSessions within this threshold are cleared from thecache. State associated with an expired session may be cleaned up by theserver at any time.

Only available when featureCompatibilityVersion is "3.6" or greater.See Backwards Incompatible Features.

  • isMaster.connectionId

New in version 4.2.

An identifier for the mongod/mongosinstance’s outgoing connection to the client.

  • isMaster.minWireVersion

New in version 2.6.

The earliest version of the wire protocol that thismongod or mongos instance is capable of usingto communicate with clients.

Clients may use minWireVersion to help negotiatecompatibility with MongoDB.

  • isMaster.maxWireVersion

New in version 2.6.

The latest version of the wire protocol that this mongodor mongos instance is capable of using to communicatewith clients.

Clients may use maxWireVersion to help negotiatecompatibility with MongoDB.

  • isMaster.readOnly

New in version 3.4.

A boolean value that, when true, indicates that themongod or mongos is running in read-only mode.

  • isMaster.compression

New in version 3.4.

An array listing the compression algorithms used or available foruse (i.e. common to both the client and the mongod ormongos instance) to compress the communicationbetween the client and the mongod ormongos instance.

The field is only available if compression is used. For example:

  • If the mongod is enabled to use both thesnappy,zlib compressors and a client has specified zlib,the compression field would contain:
  1. "compression": [ "zlib" ]
  • If the mongod is enabled to use both thesnappy,zlib compressors and a client has specified zlib,snappy,the compression field would contain:
  1. "compression": [ "zlib", "snappy" ]
  • If the mongod is enabled to use thesnappy compressor and a client has specified zlib,snappy,the compression field would contain :
  1. "compression": [ "snappy" ]
  • If the mongod is enabled to use the snappycompressor and a client has specified zlib or the client hasspecified no compressor, the field is omitted.

That is, if the client does not specify compression or if the clientspecifies a compressor not enabled for the connectedmongod or mongos instance, the fielddoes not return.

  • isMaster.saslSupportedMechs
  • An array of SASL mechanisms used to create the user’s credential orcredentials. Supported SASL mechanisms are:

    • GSSAPI
    • SCRAM-SHA-256
    • SCRAM-SHA-1The field is returned only when the command is run with thesaslSupportedMechs field:
  1. db.runCommand( { isMaster: 1, saslSupportedMechs: "<db.username>" } )

Sharded Instances

mongos instances add the following field to theisMaster response document:

  • isMaster.msg
  • Contains the value isdbgrid when isMasterreturns from a mongos instance.

Replica Sets

isMaster contains these fields when returned by a memberof a replica set:

Drivers use this array and the isMaster.passives to determinewhich members to read from.

  • isMaster.setName
  • The name of the current :replica set.
  • isMaster.setVersion

New in version 2.6.

The current replica set config version.

  • isMaster.passives
  • An array of strings in the format of "[hostname]:[port]"listing all members of the replica set which have amembers[n].priority of 0.

This field only appears if there is at least one member with amembers[n].priority of 0.

Drivers use this array and the isMaster.hosts to determinewhich members to read from.

  • isMaster.arbiters
  • An array of strings in the format of "[hostname]:[port]"listing all members of the replica set that arearbiters.

This field only appears if there is at least one arbiter in thereplica set.

  • isMaster.primary
  • A string in the format of "[hostname]:[port]" listing thecurrent primary member of the replica set.
  • isMaster.arbiterOnly
  • A boolean value that , when true, indicates that the currentinstance is an arbiter. The arbiterOnlyfield is only present, if the instance is an arbiter.
  • isMaster.passive
  • A boolean value that, when true, indicates that the currentinstance is passive. Thepassive field is only present for members with amembers[n].priority of 0.
  • isMaster.hidden
  • A boolean value that, when true, indicates that the currentinstance is hidden. Thehidden field is only present for hidden members.
  • isMaster.tags
  • A tags document contains user-defined tag field and value pairs forthe replica set member.
  1. { "<tag1>": "<string1>", "<tag2>": "<string2>",... }

See also

members[n].tags

  • isMaster.me
  • The [hostname]:[port] of the member that returnedisMaster.
  • isMaster.electionId

New in version 3.0.

A unique identifier for each election. Included only in the outputof isMaster for the primary. Used by clientsto determine when elections occur.

  • isMaster.lastWrite

New in version 3.4.

A document containing optime and date information for thedatabase’s most recent write operation.

  • isMaster.lastWrite.opTime
  • An object giving the optime of the last write operation.

  • isMaster.lastWrite.lastWriteDate

  • A date object containing thetime of the last write operation.

  • isMaster.lastWrite.majorityOpTime

  • An object giving the optime of the last write operationreadable by majority reads.

  • isMaster.lastWrite.majorityWriteDate

  • A date object containing thetime of the last write operation readable bymajority reads.

For details on the ok status field, the operationTime field,and the $clusterTime field, seeCommand Response.