Database Manual / Reference / Database Commands / Replication

replSetGetConfig (database command数据库命令)

Definition定义

replSetGetConfig

Returns a document that describes the current configuration of the replica set.返回一个描述副本集当前配置的文档。

Tip

In mongosh, this command can also be run through the rs.conf() helper method.mongosh中,此命令也可以通过rs.conf()辅助方法运行。

Helper methods are convenient for mongosh users, but they may not return the same level of information as database commands. 助手方法对mongosh用户来说很方便,但它们可能不会返回与数据库命令相同级别的信息。In cases where the convenience is not needed or the additional return fields are required, use the database command.如果不需要便利性或需要额外的返回字段,请使用database命令。

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部署的完全托管服务

Important

This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.M0和Flex集群不支持此命令。有关详细信息,请参阅不支持的命令

  • 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语法

To run, replSetGetConfig must be issued against the admin database. The command has the following syntax:要运行,必须对管理员数据库发出replSetGetConfig。该命令具有以下语法:

db.adminCommand(
{
replSetGetConfig: 1,
commitmentStatus: <boolean>,
comment: <any>
}
)

Command Fields命令字段

Field字段Type类型Description描述
replSetGetConfigany任意Any value任何值
commitmentStatusboolean布尔值

Optional. 可选。Specify true to include a commitmentStatus field in the output. 指定true以在输出中包含commitmentStatus字段。The commitmentStatus output field indicates whether the replica set's previous reconfig has been committed, so that the replica set is ready to be reconfigured again. commitmentStatus输出字段指示副本集之前的重新配置是否已提交,以便副本集可以再次重新配置。For details, see commitmentStatus Output Field.有关详细信息,请参阅commitmentStatus输出字段

You can only specify commitmentStatus: true option when running the command on the primary. The command errors if run with commitmentStatus: true on a secondary.在主服务器上运行命令时,只能指定commitmentStatus:true选项。如果在辅助服务器上以commitmentStatus:true运行该命令,则会出现错误。

commentany任意

Optional. 可选。A user-provided comment to attach to this command. Once set, this comment appears alongside records of this command in the following locations:用户提供了要附加到此命令的注释。设置后,此注释将与此命令的记录一起出现在以下位置:

A comment can be any valid BSON type (string, integer, object, array, etc).注释可以是任何有效的BSON类型(字符串、整数、对象、数组等)。

mongosh provides the rs.conf() method that wraps the replSetGetConfig command:提供了rs.conf()方法,该方法封装了replSetGetConfig命令:

rs.conf();

Output Example输出示例

The following is an example output of the replSetGetConfig command run with commitmentStatus: true on the primary:以下是在主服务器上使用commitmentStatus: true运行replSetGetConfig命令的示例输出:

{
"config" : {
"_id" : "myRepl",
"version" : 180294,
"term" : 1,
"protocolVersion" : Long(1),
"writeConcernMajorityJournalDefault" : true,
"members" : [
{
"_id" : 0,
"host" : "m1.example.net:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {

},
"secondaryDelaySecs" : Long(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "m2.example.net:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {

},
"secondaryDelaySecs" : Long(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "m3.example.net:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {

},
"secondaryDelaySecs" : Long(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : -1,
"catchUpTakeoverDelayMillis" : 30000,
"getLastErrorModes" : {

},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5eaa1e9ac4d650aa7817623d")
}
},
"commitmentStatus" : true,
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1588212091, 1),
"signature" : {
"hash" : BinData(0,"veOHa2mOeRTzuR0LKqnzGxWV77k="),
"keyId" : Long("6821298283919441923")
}
},
"operationTime" : Timestamp(1588212091, 1)
}
Field字段Description描述
configThe replica set configuration. For description of each configuration settings, see Self-Managed Replica Set Configuration.副本集配置。有关每个配置设置的说明,请参阅自我管理副本集配置
commitmentStatus

A boolean that indicates whether the most recent replica set configuration has been committed; i.e.一个布尔值,指示是否已提交最新的副本集配置;即。

  • The most recent replica set configuration for the primary has propagated to a majority of members, and主服务器的最新副本集配置已传播到大多数成员,并且
  • The last write operation to the replica set with the previous configuration has been majority-commited in the new configuration.对具有先前配置的副本集的最后一次写入操作已在新配置中大部分完成。

If true, then the configuration has been committed, and the replica set can be reconfigured. 如果为true,则配置已提交,可以重新配置副本集。To reconfigure the replica set, see replSetReconfig command or the mongosh method rs.reconfig().要重新配置副本集,请参阅replSetReconfig命令或mongosh方法rs.reconfig()

If false, then the configuration has not been committed, and the replica set cannot be reconfigured.如果为false,则配置尚未提交,副本集无法重新配置。

okA number that indicates whether the command has succeeded (1) or failed (0).一个数字,指示命令是成功(1)还是失败(0)。
operationTime
$clusterTime
Returned with every command for a replica set. See db.adminCommand Response for details.与副本集的每个命令一起返回。有关详细信息,请参阅db.adminCommand响应