翻译或纠错本页面

分片状态

shardingState

shardingState is an admin command that reports if mongod is a member of a sharded cluster. shardingState has the following prototype form:

{ shardingState: 1 }

使用 shardingState 来检测一个 mongod 是否为集群的成员, mongod 必须满足以下条件:

  1. mongod 为复制集中的主节点,且

  2. the mongod instance is a member of a sharded cluster.

如果 shardingState 检测到 mongod 是集群中的一员,命令返回如下结构的数据:

{
  "enabled" : true,
  "configServer" : "<configdb-string>",
  "shardName" : "<string>",
  "shardHost" : "string:",
  "versions" : {
       "<database>.<collection>" : Timestamp(<...>),
       "<database>.<collection>" : Timestamp(<...>)
  },
  "ok" : 1
}

否则,命令 shardingState 返回以下文档:

{ "note" : "from execCommand", "ok" : 0, "errmsg" : "not master" }

配置服务器 使用:dbcommand:shardingState 得到的返回是:

{ "enabled": false, "ok": 1 }

注解

mongos instances do not provide the shardingState.

警告

这个命令会获得数据库的写锁并阻塞其他操作,不过,这个操作往往很快就执行完.