“文档” 菜单
文档首页
/
MongoDB Manual
/ /

查看集群配置

在此页面上

  • 列出已启用分片的数据库
  • 列出分片
  • 查看集群详细信息

要列出已启用分片的数据库,请在配置数据库中查询 databases集合。如果partitioned字段的值为true ,则数据库已启用分片。将 mongosh连接到mongos实例并运行以下操作,以获取已启用分片的数据库的完整列表:

use config
db.databases.find( { "partitioned": true } )

例子

您可以使用下列命令,返回一个集群中所有数据库的列表:

use config
db.databases.find()

如果返回以下结果集:

{ "_id" : "test", "primary" : "shardB", "partitioned" : false }
{ "_id" : "animals", "primary" : "shardA", "partitioned" : true }
{ "_id" : "farms", "primary" : "shardA", "partitioned" : false }

则仅对 animals 数据库启用分片。

要列出当前配置的分片集,请使用 listShards 命令,如下所示:

db.adminCommand( { listShards : 1 } )

要查看集群详细信息,请执行 db.printShardingStatus()sh.status()。这两个方法返回相同的输出。

例子

在以下示例中 sh.status() 的输出

  • sharding version 显示分片元数据的版本号。

  • shards 显示在集群中用作分片的 mongod 实例的列表。

  • databases 显示集群中的所有数据库,包括未启用分片的数据库。

  • 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" }

后退

替换配置服务器

来年

重启分片集群