On this page本页内容
isMaster
¶isMaster
returns a document that describes the role of the mongod
instance. If the optional field saslSupportedMechs
is specified, the command also returns an array of SASL mechanisms
used to create the specified user’s credentials.
If the instance is a member of a replica set, then isMaster
returns 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 mongod
instance that is not a member of a replica set, isMaster
returns a subset of this information.
MongoDB drivers and clients use isMaster
to determine the state of the replica set members and to discover additional members of a replica set.
The command takes the following form:
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.
The db.isMaster()
method in the mongo
shell provides a wrapper around isMaster
.
The following isMaster
fields are common across all roles:
isMaster.
ismaster
¶A boolean value that reports when this node is writable. If true
, then this instance is a primary in a replica set, or a mongos
instance, or a standalone mongod
.
This field will be false
if the instance is a secondary member of a replica set or if the member is an arbiter of a replica set.
isMaster.
topologyVersion
¶For internal use by MongoDB.
New in version 4.4.版本4.4中的新功能。
isMaster.
maxBsonObjectSize
¶The maximum permitted size of a BSON object in bytes for this mongod
process. If not provided, clients should assume 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 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,000
writes.
Changed in version 3.6.在版本3.6中更改。The limit raises from 1,000
to 100,000
writes. This limit also applies to legacy OP_INSERT
messages.
isMaster.
logicalSessionTimeoutMinutes
¶New in version 3.6.版本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 refreshSessions
within 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 featureCompatibilityVersion
is "3.6"
or greater. See Backwards Incompatible Features.
isMaster.
connectionId
¶New in version 4.2.版本4.2中的新功能。
An identifier for the mongod
/mongos
instance’s outgoing connection to the client.
isMaster.
minWireVersion
¶The earliest version of the wire protocol that this mongod
or mongos
instance is capable of using to communicate with clients.
Clients may use minWireVersion
to help negotiate compatibility with MongoDB.
isMaster.
maxWireVersion
¶The latest version of the wire protocol that this mongod
or mongos
instance is capable of using to communicate with clients.
Clients may use maxWireVersion
to help negotiate compatibility with MongoDB.
isMaster.
readOnly
¶New in version 3.4.版本3.4中的新功能。
A boolean value that, when true
, indicates that the mongod
or mongos
is running in read-only mode.
isMaster.
compression
¶New in version 3.4.版本3.4中的新功能。
An array listing the compression algorithms used or available for use (i.e. common to both the client and the mongod
or mongos
instance) to compress the communication between the client and the mongod
or mongos
instance.
The field is only available if compression is used. For example:例如:
mongod
is enabled to use both the snappy,zlib
compressors and a client has specified zlib
, the compression
field would contain:
mongod
is enabled to use both the snappy,zlib
compressors and a client has specified zlib,snappy
, the compression
field would contain:
mongod
is enabled to use the snappy
compressor and a client has specified zlib,snappy
, the compression
field would contain :
mongod
is enabled to use the snappy
compressor and a client has specified zlib
or 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 mongod
or mongos
instance, the field does not return.
isMaster.
saslSupportedMechs
¶An array of SASL mechanisms used to create the user’s credential or credentials. Supported SASL mechanisms are:
GSSAPI
SCRAM-SHA-256
SCRAM-SHA-1
The field is returned only when the command is run with the saslSupportedMechs
field:
isMaster
contains these fields when returned by a member of a replica set:
isMaster.
hosts
¶An 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.passives
to determine which members to read from.
isMaster.
setName
¶The name of the current :replica set.
isMaster.
setVersion
¶The current replica set config version.
isMaster.
secondary
¶A boolean value that, when true
, indicates if the mongod
is a secondary member of a replica set.
isMaster.
passives
¶An array of strings in the format of "[hostname]:[port]"
listing all members of the replica set which have a members[n].priority
of 0
.
This field only appears if there is at least one member with a members[n].priority
of 0
.
Drivers use this array and the isMaster.hosts
to determine which members to read from.
isMaster.
arbiters
¶An 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.
primary
¶A string in the format of "[hostname]:[port]"
listing the current primary member of the replica set.
isMaster.
arbiterOnly
¶A boolean value that , when true
, indicates that the current instance is an arbiter. The arbiterOnly
field is only present, if the instance is an arbiter.
isMaster.
passive
¶A boolean value that, when true
, indicates that the current instance is passive. The passive
field is only present for members with a members[n].priority
of 0
.
A boolean value that, when true
, indicates that the current instance is hidden. The hidden
field is only present for hidden members.
A tags
document contains user-defined tag field and value pairs for the replica set member.
settings.getLastErrorModes
and settings.getLastErrorDefaults
.For more information, see Configure Replica Set Tag Sets.
See also参阅
isMaster.
electionId
¶A unique identifier for each election. Included only in the output of isMaster
for the primary. Used by clients to determine when elections occur.
isMaster.
lastWrite
¶New in version 3.4.版本3.4中的新功能。
A document containing optime and date information for the database’s most recent write operation.
isMaster.lastWrite.
lastWriteDate
¶A date object containing the time of the last write operation.
For details on the ok
status field, the operationTime
field, and the $clusterTime
field, see Command Response.