翻译或纠错本页面

isMaster

On this page

Definition

isMaster

isMaster returns a document that describes the role of the mongod instance.

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 db.isMaster() method in the mongo shell provides a wrapper around isMaster.

The command takes the following form:

{ isMaster: 1 }

参见

db.isMaster()

Output

All Instances

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 master in a master-slave configuration, 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.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

2.4 新版功能.

The maximum permitted size of a BSON wire protocol message. The default value is 48000000 bytes.

isMaster.localTime

Returns the local server time in UTC. This value is an ISO date.

isMaster.minWireVersion

2.6 新版功能.

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

2.6 新版功能.

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.

Sharded Instances

mongos instances add the following field to the isMaster response document:

isMaster.msg

Contains the value isdbgrid when isMaster returns from a mongos instance.

Replica Sets

isMaster contains these fields when returned by a member of a replica set:

isMaster.setName

The name of the current :replica set.

isMaster.setVersion

2.6 新版功能.

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.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.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.

isMaster.hidden

A boolean value that, when true, indicates that the current instance is hidden. The hidden field is only present for hidden members.

isMaster.tags

A tag set document containing mappings of arbitrary keys and values. These documents describe replica set members in order to customize write concern and read preference and thereby allow configurable data center awareness.

This field is only present if there are tags assigned to the member. See 配置复制集标签设置 for more information.

isMaster.me

The [hostname]:[port] of the member that returned isMaster.

isMaster.electionId

3.0.0 新版功能.

A unique identifier for each election. Included only in the output of isMaster for the primary. Used by clients to determine when elections occur.

←   applyOps replSetGetConfig  →