- Reference >
- Database Commands >
- Sharding Commands >
- shardingState
shardingState¶
-
shardingState¶ shardingStateis an admin command that reports ifmongodis a member of a sharded cluster.shardingStatehas the following prototype form:{ shardingState: 1 }
For
shardingStateto detect that amongodis a member of a sharded cluster, themongodmust satisfy the following conditions:- the
mongodis a primary member of a replica set, and - the
mongodinstance is a member of a sharded cluster.
If
shardingStatedetects that amongodis a member of a sharded cluster,shardingStatereturns a document that resembles the following prototype:{ "enabled" : true, "configServer" : "<configdb-string>", "shardName" : "<string>", "shardHost" : "string:", "versions" : { "<database>.<collection>" : Timestamp(<...>), "<database>.<collection>" : Timestamp(<...>) }, "ok" : 1 }
Otherwise,
shardingStatewill return the following document:{ "note" : "from execCommand", "ok" : 0, "errmsg" : "not master" }
The response from
shardingStatewhen used with a config server is:{ "enabled": false, "ok": 1 }
Note
mongosinstances do not provide theshardingState.Warning
This command obtains a write lock on the affected database and will block other operations until it has completed; however, the operation is typically short lived.
- the