|
Here we present a list of useful commands for obtaining information about a sharding cluster. To set up a sharding cluster, see the docs on sharding configuration. Identifying a Shard Cluster// Test if we're speaking to a mongos process or // straight to a mongod process > db.runCommand({ isdbgrid : 1}); // if connected to mongos, this command returns { ismaster: 0.0, msg: "isdbgrid" } > db.runCommand({ismaster:1}); List Existing Shards> db.runCommand({ listshards : 1});
{"servers" :
[{"_id" : ObjectId( "4a9d40c981ba1487ccfaa634") ,
"host" : "localhost:10000"},
{"_id" : ObjectId( "4a9d40df81ba1487ccfaa635") ,
"host" : "localhost:10001"}
],
"ok" : 1
}
List Which Databases are ShardedHere we query the config database, albeit through mongos. The getSisterDB command is used to return the config database. > config = db.getSisterDB("config")
> config.system.namespaces.find()
View Sharding Details> use admin > db.printShardingStatus(); // A very basic sharding configuration on localhost sharding version: { "_id" : 1, "version" : 2 } shards: { "_id" : ObjectId("4bd9ae3e0a2e26420e556876"), "host" : "localhost:30001" } { "_id" : ObjectId("4bd9ae420a2e26420e556877"), "host" : "localhost:30002" } { "_id" : ObjectId("4bd9ae460a2e26420e556878"), "host" : "localhost:30003" } databases: { "name" : "admin", "partitioned" : false, "primary" : "localhost:20001", "_id" : ObjectId("4bd9add2c0302e394c6844b6") } my chunks { "name" : "foo", "partitioned" : true, "primary" : "localhost:30002", "sharded" : { "foo.foo" : { "key" : { "_id" : 1 }, "unique" : false } }, "_id" : ObjectId("4bd9ae60c0302e394c6844b7") } my chunks foo.foo { "_id" : { $minKey : 1 } } -->> { "_id" : { $maxKey : 1 } } on : localhost:30002 { "t" : 1272557259000, "i" : 1 } Notice the output to the printShardingStatus command. First, we see the locations the the three shards comprising the cluster. Next, the various databases living on the cluster are displayed. The first database shown is the admin database, which has not bee partitioned. The primary field indicates the location of the database, which, in the case of the admin database, is on the config server running on port 20001. The second database is partitioned, and it's easy to see the shard key and the location and ranges of chunks comprising the partition. Since there's no data in the foo database, only a single chunk exists. That single chunk includes the entire range of possible shard keys. Chunk OperationsMongoDB v1.6 will managing the arrangement chunks automatically. However, it may be desirable to move a chunk manually; here's the command to do that:
db.runCommand( { movechunk : "test.blog.posts" ,
find : { author : "eliot" } ,
to : "shard1" } )
Parameters:
|

PLEASE POST QUESTIONS IN THE USER GROUPS FORUM. Post non-question comments and helpful hints here.
blog comments powered by Disqus