Database Reference
In-Depth Information
the ability to add and remove shards to and from your cluster without having to take it offline is a critical
component of MongodB's ability to support highly scalable, highly available, large-capacity datastores. this satisfies the
final requirement: “requirement 3: the ability to add or remove shards while the system is running.”
Note
Determining How You're Connected
Your application can be connected either to a standard nonsharded database ( mongod ) or to a shard controller
( mongos ). MongoDB makes both of these processes; for all but a few use cases, the database and shard controller look
and behave exactly the same way. However, sometimes it may be important to determine what type of system you are
connected to.
MongoDB provides the isdbgrid command, which you can use to interrogate the connected data system to
determine whether it is sharded. The following snippet shows how to use this command, as well as what its output
looks like:
$mongo
>use testdb
>db.runCommand({ isdbgrid : 1});
{ "isdbgrid" : 1, "hostname" : "Pixl.local", "ok" : 1 }
The response includes the isdbgrid:1 field, which tells you that the database you are connected to is enabled for
sharding. A response of isdbgrid:0 would indicate that you are connected to a nonsharded database.
Listing the Status of a Sharded Cluster
MongoDB also includes a simple command for dumping the status of a sharding cluster: printShardingStatus() .
This command can give you a lot of insight into the internals of the sharding system. The following snippet shows
how to invoke the printShardingStatus() command, but strips out some of the output returned to make it easier
to read:
$mongo localhost:27021
>sh.status();
--- Sharding Status ---
sharding version: {
"_id" : 1,
"version" : 3,
"minCompatibleVersion" : 3,
"currentVersion" : 4,
"clusterId" : ObjectId("51c699a7dd9fc53b6cdc4718")
}
shards:
{ "_id" : "shard0000", "host" : "localhost:27023" }
{ "_id" : "shard0001", "host" : "localhost:27024" }
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "test", "partitioned" : false, "primary" : "shard0000" }
{ "_id" : "testdb", "partitioned" : true, "primary" : "shard0000" }
testdb.testcollection
shard key: { "testkey" : 1 }
 
 
Search WWH ::




Custom Search