isMaster
Definition
isMaster
isMaster
returns a document that describes the role ofthemongod
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:
- 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.
- 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 isMaster
disconnects 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. If
true
, then this instance is a primary in areplica set, or amongos
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 this
limit
, 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.
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.
New in version 4.2.
An identifier for the mongod
/mongos
instance’s outgoing connection to the client.
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.
New in version 2.6.
The latest version of the wire protocol that this mongod
or mongos
instance is capable of using to communicatewith clients.
Clients may use maxWireVersion
to help negotiatecompatibility with MongoDB.
New in version 3.4.
A boolean value that, when true
, indicates that themongod
or mongos
is running in read-only mode.
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 specifiedzlib
,thecompression
field would contain:
- "compression": [ "zlib" ]
- If the
mongod
is enabled to use both thesnappy,zlib
compressors and a client has specifiedzlib,snappy
,thecompression
field would contain:
- "compression": [ "zlib", "snappy" ]
- If the
mongod
is enabled to use thesnappy
compressor and a client has specifiedzlib,snappy
,thecompression
field would contain :
- "compression": [ "snappy" ]
- If the
mongod
is enabled to use thesnappy
compressor and a client has specifiedzlib
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-1
The field is returned only when the command is run with thesaslSupportedMechs
field:
- db.runCommand( { isMaster: 1, saslSupportedMechs: "<db.username>" } )
Sharded Instances
mongos
instances add the following field to theisMaster
response document:
Replica Sets
isMaster
contains these fields when returned by a memberof a replica set:
isMaster.
hosts
- An array of strings in the format of
"[hostname]:[port]"
thatlists all members of the replica set that are neitherhidden, passive,nor arbiters.
Drivers use this array and the isMaster.passives
to determinewhich members to read from.
New in version 2.6.
The current replica set config version.
isMaster.
secondary
- A boolean value that, when
true
, indicates if themongod
is a secondary member of a replicaset.
isMaster.
passives
- An array of strings in the format of
"[hostname]:[port]"
listing all members of the replica set which have amembers[n].priority
of0
.
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. ThearbiterOnly
field 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
of0
.
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.
- { "<tag1>": "<string1>", "<tag2>": "<string2>",... }
- For read operations, you can specify a tag set in the readpreference to direct theoperations to replica set member(s) with the specified tag(s).
- For write operations, you can create a customize write concern using
settings.getLastErrorModes
andsettings.getLastErrorDefaults
.For more information, seeConfigure Replica Set Tag Sets.
See also
isMaster.
me
- The
[hostname]:[port]
of the member that returnedisMaster
.
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.
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.
A date object containing thetime of the last write operation.
An object giving the optime of the last write operationreadable by
majority
reads.- A date object containing thetime of the last write operation readable by
majority
reads.
For details on the ok
status field, the operationTime
field,and the $clusterTime
field, seeCommand Response.