Database Manual / Reference / Database Commands / Replication

hello (database command数据库命令)

Definition定义

hello

New in version 4.2.在版本4.2中新增。

hello returns a document that describes the role of the mongod instance. 返回一个描述mongod实例角色的文档。If the optional field saslSupportedMechs is specified, the command also returns an array of SASL mechanisms used to create the specified user's credentials.如果指定了可选字段saslSupportedMechs,则该命令还将返回用于创建指定用户凭据的SASL机制数组

If the instance is a member of a replica set, then hello returns a subset of the replica set configuration and status including whether or not the instance is the primary of the replica set.如果实例是副本集的成员,则hello将返回副本集配置和状态的子集,包括实例是否是副本集中的primary

When sent to a mongod instance that is not a member of a replica set, hello returns a subset of this information.当发送到不是副本集成员的mongod实例时,hello会返回此信息的子集。

MongoDB drivers and clients use hello to determine the state of the replica set members and to discover additional members of a replica set.MongoDB驱动程序客户端使用hello来确定副本集成员的状态,并发现副本集的其他成员。

Compatibility兼容性

This command is available in deployments hosted in the following environments:此命令在以下环境中托管的部署中可用:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务

Note

This command is supported in all MongoDB Atlas clusters. 所有MongoDB Atlas集群都支持此命令。For information on Atlas support for all commands, see Unsupported Commands.有关Atlas支持所有命令的信息,请参阅不支持的命令

  • MongoDB Enterprise: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本
  • MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本

Syntax语法

The command has the following syntax:该命令具有以下语法:

db.runCommand(
{
hello: 1
}
)

The hello command accepts optional fields saslSupportedMechs: <db.user> to return an additional field hello.saslSupportedMechs in its result and comment <any> to add a log comment associated with the command.hello命令接受可选字段saslSupportedMechs: <db.user>以在其结果中返回额外的字段hello.saslSupportedMechs,并接受comment <any>以添加与该命令关联的日志注释。

db.runCommand(
{
hello: 1,
saslSupportedMechs: "<db.username>",
comment: <any>
}
)

The db.hello() method in mongosh provides a wrapper around hello.mongosh中的db.hello()方法为hello提供了一个包装器。

Behavior行为

Client Disconnection客户端断开连接

If the client that issued hello disconnects before the operation completes, MongoDB marks hello for termination using killOp.如果发出hello的客户端在操作完成之前断开连接,MongoDB将使用killOp标记hello以终止。

Output输出

All Instances所有实例

The following hello fields are common across all roles:以下hello字段在所有角色中都很常见:

hello.isWritablePrimary

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.如果为true,则此实例是副本集中的primarymongos实例或独立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.如果该实例是副本集的次要成员,或者该成员是副本集中的仲裁器,则此字段将为false

hello.topologyVersion
For internal use by MongoDB.供MongoDB内部使用。
hello.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".mongod进程允许的BSON对象的最大大小(以字节为单位)。如果没有提供,客户端应假设最大大小为“16*1024*1024”。
hello.maxMessageSizeBytes
The maximum permitted size of a BSON wire protocol message. The default value is 48000000 bytes.BSON有线协议消息的最大允许大小。默认值为48000000字节。
hello.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.此限制的值为100000次写入。

hello.localTime
Returns the local server time in UTC. This value is an ISO date.返回以UTC为单位的本地服务器时间。此值是ISO日期
hello.logicalSessionTimeoutMinutes

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.未从客户端接收到新的读/写操作或在此阈值内使用refreshSessions刷新的会话将从缓存中清除。服务器可以随时清理与过期会话相关联的状态。

Only available when featureCompatibilityVersion is "3.6" or greater.仅当featureCompatibilityVersion"3.6"或更高版本时可用。

hello.connectionId
An identifier for the mongod / mongos instance's outgoing connection to the client.mongod/mongos实例到客户端的传出连接的标识符。
hello.minWireVersion

The earliest version of the wire protocol that this mongod or mongos instance is capable of using to communicate with clients.mongodmongos实例能够用于与客户端通信的最早版本的有线协议。

Clients may use minWireVersion to help negotiate compatibility with MongoDB.客户端可以使用minWireVersion来帮助协商与MongoDB的兼容性。

hello.maxWireVersion

The latest version of the wire protocol that this mongod or mongos instance is capable of using to communicate with clients.mongodmongos实例能够用于与客户端通信的最新版本的有线协议。

Clients may use maxWireVersion to help negotiate compatibility with MongoDB.客户端可以使用maxWireVersion来帮助协商与MongoDB的兼容性。

hello.readOnly
A boolean value that, when true, indicates that the mongod or mongos is running in read-only mode.一个布尔值,当为true时,表示mongodmongos正在以只读模式运行。
hello.compression

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.一个数组,列出了用于压缩客户端和mongodmongos实例之间通信的压缩算法(即客户端和mongood或mongos实例共有的压缩算法)。

The field is only available if compression is used. For example:该字段仅在使用压缩时可用。例如:

  • If the mongod is enabled to use both the snappy,zlib compressors and a client has specified zlib, the compression field would contain:如果mongod启用了snappyzlib压缩器,并且客户端指定了zlib,则压缩字段将包含:

    "compression": [ "zlib" ]
  • If the mongod is enabled to use both the snappy,zlib compressors and a client has specified zlib,snappy, the compression field would contain:如果mongod启用了snappy,zlib压缩器,并且客户端指定了snappy,zlib,则compression字段将包含:

    "compression": [ "zlib", "snappy" ]
  • If the mongod is enabled to use the snappy compressor and a client has specified zlib,snappy, the compression field would contain :如果mongod启用了snappy压缩器,并且客户端指定了zlib,snappy,则compression字段将包含:

    "compression": [ "snappy" ]
  • If the 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.如果启用了mongod来使用snappy压缩器,并且客户端指定了zlib,或者客户端没有指定压缩器,则省略该字段。

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.也就是说,如果客户端没有指定压缩,或者客户端指定了一个未为连接的mongodmongos实例启用的压缩器,则该字段不会返回。

hello.saslSupportedMechs

An array of SASL mechanisms used to create the user's credential or credentials. Supported SASL mechanisms are:一系列用于创建用户凭据的SASL机制。支持的SASL机制包括:

  • GSSAPI
  • SCRAM-SHA-256
  • SCRAM-SHA-1

The field is returned only when the command is run with the saslSupportedMechs field:仅当使用saslSupportedMechs字段运行命令时,才会返回该字段:

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

Sharded Instances分片实例

mongos instances add the following field to the hello response document:实例将以下字段添加到hello响应文档中:

hello.msg
Contains the value isdbgrid when hello returns from a mongos instance.包含从mongos实例返回hello时的值isdbgrid

Replica Sets复制集

hello contains these fields when returned by a member of a replica set:当副本集的成员返回时,包含以下字段:

hello.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.一个字符串数组,格式为"[hostname]:[port]",列出了副本集中既不是隐藏的被动的也不是仲裁器的所有成员。

Drivers use this array and the hello.passives to determine which members to read from.驱动程序使用此数组和hello.passives来确定从哪些成员读取。

hello.setName
The name of the current :replica set.当前副本集的名称。
hello.setVersion
The current replica set config version.当前副本集配置版本。
hello.secondary
A boolean value that, when true, indicates if the mongod is a secondary member of a replica set.一个布尔值,当为true时,表示mongod是否是副本集次要成员。
hello.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.一个字符串数组,格式为"[hostname]:[port]",列出了副本集members[n].priority0的所有成员。

This field only appears if there is at least one member with a members[n].priority of 0.仅当至少有一个members[n].priority0时,才会显示此字段。

Drivers use this array and the hello.hosts to determine which members to read from.驱动程序使用此数组和hello.hosts来确定从哪些成员读取。

hello.arbiters

An array of strings in the format of "[hostname]:[port]" listing all members of the replica set that are arbiters.一个字符串数组,格式为"[hostname]:[port]",列出了副本集中作为仲裁器的所有成员。

This field only appears if there is at least one arbiter in the replica set.仅当副本集中至少有一个仲裁器时,才会显示此字段。

hello.primary
A string in the format of "[hostname]:[port]" listing the current primary member of the replica set.一个格式为"[hostname]:[port]"的字符串,列出了副本集的当前primary成员。
hello.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.一个布尔值,当为true时,表示当前实例是仲裁器。只有当实例是仲裁器时,arbiterOnly字段才存在。
hello.passive
A boolean value that, when true, indicates that the current instance is passive. 一个布尔值,当为true时,表示当前实例是被动的The passive field is only present for members with a members[n].priority of 0.passive字段仅适用于members[n].priority0的成员。
hello.hidden
A boolean value that, when true, indicates that the current instance is hidden. The hidden field is only present for hidden members.一个布尔值,当为true时,表示当前实例已隐藏hidden字段仅对隐藏成员存在。
hello.tags

A tags document contains user-defined tag field and value pairs for the replica set member.tags文档包含用户定义的标记字段和副本集成员的值对。

{ "<tag1>": "<string1>", "<tag2>": "<string2>",... }

For more information, see Configure Replica Set Tag Sets.有关详细信息,请参阅配置副本集标记集

hello.me
The [hostname]:[port] of the member that returned hello.返回hello的成员的[hostname]:[port]
hello.electionId
A unique identifier for each election. Included only in the output of hello for the primary. Used by clients to determine when elections occur.每次选举的唯一标识符。仅包含在primaryhello输出中。客户使用它来确定选举何时发生。
hello.lastWrite

A document containing optime and date information for the database's most recent write operation.包含数据库最近写入操作的最佳值和日期信息的文档。

hello.lastWrite.opTime
An object giving the optime of the last write operation.给出上次写入操作optime(最优值)的对象。
hello.lastWrite.lastWriteDate
A date object containing the time of the last write operation.包含上次写入操作时间的日期对象。
hello.lastWrite.majorityOpTime
An object giving the optime of the last write operation readable by majority reads.一个对象,给出majority读取可读的最后一次写入操作的optime(最优值)。
hello.lastWrite.majorityWriteDate
A date object containing the time of the last write operation readable by majority reads.一个日期对象,包含majority读取可读的最后一次写入操作的时间。

For details on the ok status field, the operationTime field, and the $clusterTime field, see Command Response.有关ok状态字段、operationTime字段和$clusterTime字段的详细信息,请参阅命令响应