shardingState
shardingState
shardingState
is an admin command that reports ifmongod
is a member of a sharded cluster.
shardingState
has the following prototype form:
- { shardingState: 1 }
To run the command, you must run against the admin
database. Seedb.adminCommand()
.
Behavior
For shardingState
to detect that a mongod
is amember of a sharded cluster, the mongod
must satisfy thefollowing conditions:
- the
mongod
is a primary member of a replica set, and - the
mongod
instance is a member of a shardedcluster.IfshardingState
detects that amongod
is amember of a sharded cluster,shardingState
returns adocument that resembles the following prototype:
- {
- "enabled" : true,
- "configServer" : "<configdb-string>",
- "shardName" : "<string>",
- "shardHost" : "string:",
- "versions" : {
- "<database>.<collection>" : Timestamp(<...>),
- "<database>.<collection>" : Timestamp(<...>)
- },
- "ok" : 1,
- "$clusterTime" : {
- "clusterTime" : Timestamp(1510716515, 1),
- "signature" : {
- "hash" : BinData(0,"B2ViX7XLzFLS5Fl9XEuFXbwKIM4="),
- "keyId" : NumberLong("6488045157173166092")
- }
- },
- "operationTime" : Timestamp(1510716515, 1)
- }
Otherwise, shardingState
will return the following document:
- {
- "enabled" : false,
- "ok" : 1,
- "$clusterTime" : {
- "clusterTime" : Timestamp(1510716515, 1),
- "signature" : {
- "hash" : BinData(0,"B2ViX7XLzFLS5Fl9XEuFXbwKIM4="),
- "keyId" : NumberLong("6488045157173166092")
- }
- },
- "operationTime" : Timestamp(1510716515, 1)
- }
The response from shardingState
when used with aconfig server is:
- {
- "enabled" : false,
- "ok" : 1,
- "operationTime" : Timestamp(1510767613, 1),
- "$gleStats" : {
- "lastOpTime" : Timestamp(0, 0),
- "electionId" : ObjectId("7fffffff0000000000000001")
- },
- "$clusterTime" : {
- "clusterTime" : Timestamp(1510767613, 1),
- "signature" : {
- "hash" : BinData(0,"IwBZ4SZjIMI5NdM62NObV/R31GM="),
- "keyId" : NumberLong("6488693018630029321")
- }
- }
- }
Note
mongos
instances do not provide theshardingState
.
Warning
This command obtains a write lock on the affected database andwill block other operations until it has completed; however, theoperation is typically short lived.