View Cluster Configuration查看群集配置
On this page本页内容
List Databases with Sharding Enabled列出启用了共享的数据库
To list the databases that have sharding enabled, query the 要列出已启用分片的数据库,请在databases collection in the Config Database. config数据库中查询databases集合。A database has sharding enabled if the value of the 如果partitioned field is true. partitioned字段的值为true,则数据库已启用分片。Connect 将mongosh to a mongos instance and run the following operation to get a full list of databases with sharding enabled:mongosh连接到mongos实例,并运行以下操作以获取启用了分片的数据库的完整列表:
use config
db.databases.find( { "partitioned": true } )
You can use the following sequence of commands to return a list of all databases in the cluster:可以使用以下命令序列返回群集中所有数据库的列表:
use config
db.databases.find()
If this returns the following result set:如果返回以下结果集:
{ "_id" : "test", "primary" : "shardB", "partitioned" : false }
{ "_id" : "animals", "primary" : "shardA", "partitioned" : true }
{ "_id" : "farms", "primary" : "shardA", "partitioned" : false }
Then sharding is only enabled for the 然后只对animals database.animals数据库启用分片。
List Shards列出分片
To list the current set of configured shards, use the 要列出当前配置的分片集,请使用listShards command, as follows:listShards命令,如下所示:
db.adminCommand( { listShards : 1 } )
View Cluster Details查看群集详细信息
To view cluster details, issue 要查看集群详细信息,请发出db.printShardingStatus() or sh.status(). Both methods return the same output.db.printShardingStatus()或sh.status()。两种方法都返回相同的输出。
In the following example output from sh.status()在下面的示例中,sh.status()的输出
sharding versiondisplays the version number of the shard metadata.显示分片元数据的版本号。shardsdisplays a list of themongodinstances used as shards in the cluster.shards显示集群中用作分片的mongod实例的列表。databasesdisplays all databases in the cluster, including database that do not have sharding enabled.显示集群中的所有数据库,包括未启用分片的数据库。Thechunksinformation for thefoodatabase displays how many chunks are on each shard and displays the range of each chunk.foo数据库的chunks信息显示每个分片上有多少块,并显示每个块的范围。
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("59a4443c3d38cd8a0b40316d")
}
shards:
{ "_id" : "shard0000", "host" : "m0.example.net:27018" }
{ "_id" : "shard0001", "host" : "m3.example2.net:27018" }
{ "_id" : "shard0002", "host" : "m2.example.net:27018" }
active mongoses:
"3.4.7" : 1
autosplit:
Currently enabled: yes
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
1 : Success
databases:
{ "_id" : "foo", "partitioned" : true, "primary" : "shard0000" }
foo.contacts
shard key: { "zip" : 1 }
unique: false
balancing: true
chunks:
shard0001 2
shard0002 3
shard0000 2
{ "zip" : { "$minKey" : 1 } } -->> { "zip" : "56000" } on : shard0001 { "t" : 2, "i" : 0 }
{ "zip" : 56000 } -->> { "zip" : "56800" } on : shard0002 { "t" : 3, "i" : 4 }
{ "zip" : 56800 } -->> { "zip" : "57088" } on : shard0002 { "t" : 4, "i" : 2 }
{ "zip" : 57088 } -->> { "zip" : "57500" } on : shard0002 { "t" : 4, "i" : 3 }
{ "zip" : 57500 } -->> { "zip" : "58140" } on : shard0001 { "t" : 4, "i" : 0 }
{ "zip" : 58140 } -->> { "zip" : "59000" } on : shard0000 { "t" : 4, "i" : 1 }
{ "zip" : 59000 } -->> { "zip" : { "$maxKey" : 1 } } on : shard0000 { "t" : 3, "i" : 3 }
{ "_id" : "test", "partitioned" : false, "primary" : "shard0000" }