对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

shardingState(数据库命令)

shardingState

shardingState is an admin command that reports if mongod is a member of a sharded cluster. To run the command, you must run against the admin database. See db.adminCommand().

此命令可用于以下环境中托管的部署:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud

注意

This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.

该命令具有以下语法:

db.adminCommand(
{
shardingState: 1
}
)

For shardingState to detect that a mongod is a member of a sharded cluster, the mongod must satisfy the following conditions:

  1. mongod是副本集的主节点,并且

  2. mongod实例是分片集群的成员。

If shardingState detects that a mongod is a member of a sharded cluster, shardingState returns a document that resembles the following prototype:

{
"enabled" : true,
"configServer" : "<configdb-string>",
"shardName" : "<string>",
"shardHost" : "string:",
"versions" : {
"<database>.<collection>" : {
"placementVersion": Timestamp({ t: 1, i: 1024 }),
"timestamp": Timestamp({ t: 1682444810, i: 8 })
},
"<database>.<collection>" : {
"placementVersion": Timestamp({ t: 0, i: 0 }),
"timestamp": Timestamp({ t: 0, i: 0 })
}
},
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp({ t: 1682457265, i: 1 }),
"signature" : {
"hash" : BinData(0,"B2ViX7XLzFLS5Fl9XEuFXbwKIM4="),
"keyId" : Long("6488045157173166092")
}
},
"operationTime" : Timestamp({ t: 1682457260, i: 1 })
}

Otherwise, shardingState will return the following document:

{
"enabled" : false,
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp({t:1510716515, i: 1}),
"signature" : {
"hash" : BinData(0,"B2ViX7XLzFLS5Fl9XEuFXbwKIM4="),
"keyId" : Long("6488045157173166092")
}
},
"operationTime" : Timestamp({t: 1510716515, i: 1})
}

The response from shardingState when used with a config server is:

{
"enabled" : false,
"ok" : 1,
"operationTime" : Timestamp({t: 1510767613, i: 1}),
"$gleStats" : {
"lastOpTime" : Timestamp({t: 0, i: 0}),
"electionId" : ObjectId("7fffffff0000000000000001")
},
"$clusterTime" : {
"clusterTime" : Timestamp({t: 1510767613, i: 1}),
"signature" : {
"hash" : BinData(0,"IwBZ4SZjIMI5NdM62NObV/R31GM="),
"keyId" : Long("6488693018630029321")
}
}
}

注意

mongos instances do not provide the shardingState.

警告

此命令在受影响的数据库上获得写锁(write lock),并在完成之前阻止其他操作;但是,该操作通常是短暂的。

给本页内容打分

在此页面上