View Cluster Configuration

List Databases with Sharding Enabled

To list the databases that have sharding enabled, query thedatabases collection in the Config Database.A database has sharding enabled if the value of the partitionedfield is true. Connect to a mongos instance with amongo shell, and run the following operation to get a fulllist of databases with sharding enabled:

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

Example

You can use the following sequence of commands toreturn a list of all databases in the cluster:

  1. use config
  2. db.databases.find()

If this returns the following result set:

  1. { "_id" : "test", "primary" : "shardB", "partitioned" : false }
  2. { "_id" : "animals", "primary" : "shardA", "partitioned" : true }
  3. { "_id" : "farms", "primary" : "shardA", "partitioned" : false }

Then sharding is only enabled for the animals database.

List Shards

To list the current set of configured shards, use the listShardscommand, as follows:

  1. db.adminCommand( { listShards : 1 } )

View Cluster Details

To view cluster details, issue db.printShardingStatus() orsh.status(). Both methods return the same output.

Example

In the following example output from sh.status()

  • sharding version displays the version number of the shardmetadata.
  • shards displays a list of the mongod instancesused as shards in the cluster.
  • databases displays all databases in the cluster,including database that do not have sharding enabled.
  • The chunks information for the foo database displays howmany chunks are on each shard and displays the range of each chunk.
  1. --- Sharding Status ---
  2. sharding version: {
  3. "_id" : 1,
  4. "minCompatibleVersion" : 5,
  5. "currentVersion" : 6,
  6. "clusterId" : ObjectId("59a4443c3d38cd8a0b40316d")
  7. }
  8. shards:
  9. { "_id" : "shard0000", "host" : "m0.example.net:27018" }
  10. { "_id" : "shard0001", "host" : "m3.example2.net:27018" }
  11. { "_id" : "shard0002", "host" : "m2.example.net:27018" }
  12. active mongoses:
  13. "3.4.7" : 1
  14. autosplit:
  15. Currently enabled: yes
  16. balancer:
  17. Currently enabled: yes
  18. Currently running: no
  19. Failed balancer rounds in last 5 attempts: 0
  20. Migration Results for the last 24 hours:
  21. 1 : Success
  22. databases:
  23. { "_id" : "foo", "partitioned" : true, "primary" : "shard0000" }
  24. foo.contacts
  25. shard key: { "zip" : 1 }
  26. unique: false
  27. balancing: true
  28. chunks:
  29. shard0001 2
  30. shard0002 3
  31. shard0000 2
  32. { "zip" : { "$minKey" : 1 } } -->> { "zip" : "56000" } on : shard0001 { "t" : 2, "i" : 0 }
  33. { "zip" : 56000 } -->> { "zip" : "56800" } on : shard0002 { "t" : 3, "i" : 4 }
  34. { "zip" : 56800 } -->> { "zip" : "57088" } on : shard0002 { "t" : 4, "i" : 2 }
  35. { "zip" : 57088 } -->> { "zip" : "57500" } on : shard0002 { "t" : 4, "i" : 3 }
  36. { "zip" : 57500 } -->> { "zip" : "58140" } on : shard0001 { "t" : 4, "i" : 0 }
  37. { "zip" : 58140 } -->> { "zip" : "59000" } on : shard0000 { "t" : 4, "i" : 1 }
  38. { "zip" : 59000 } -->> { "zip" : { "$maxKey" : 1 } } on : shard0000 { "t" : 3, "i" : 3 }
  39. { "_id" : "test", "partitioned" : false, "primary" : "shard0000" }