翻译或纠错本页面
查看集群配置¶
列出所有开启分片的数据块¶
要列出所有开启分片的数据库,可以在 Config Database 的 databases 进行查询.如果一个数据库记录的 partitioned 字段值为 true ,则数据库开启了分片.通过 program:mongo 终端连接 mongos ,使用以下选项查询开启了分片的数据库列表:
use config
db.databases.find( { "partitioned": true } )
示例
You can use the following sequence of commands when to return a list of all databases in the cluster:
use config
db.databases.find()
如果返回以下结果:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "animals", "partitioned" : true, "primary" : "m0.example.net:30001" }
{ "_id" : "farms", "partitioned" : false, "primary" : "m1.example2.net:27017" }
则只有 animals 数据库开启了分片.
查看集群细节¶
使用 db.printShardingStatus() 或者 sh.status() 查看集群细节,两个命令是等价的.
示例
In the following example output from sh.status()
sharding version 显示了集群元信息的版本信息.
shards 显示了集群中被用作分片的 mongod 列表.
databases 显示了集群中所有的数据库列表,包含没有开启分片的数据库.
foo 数据库中的 chunks 信息显示了每个分片有几个数据块与数据块的范围.
--- Sharding Status ---
sharding version: { "_id" : 1, "version" : 3 }
shards:
{ "_id" : "shard0000", "host" : "m0.example.net:30001" }
{ "_id" : "shard0001", "host" : "m3.example2.net:50000" }
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "contacts", "partitioned" : true, "primary" : "shard0000" }
foo.contacts
shard key: { "zip" : 1 }
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" }