- Reference >
- Database Commands >
- Sharding Commands >
- removeShard
removeShard¶
- removeShard¶
Removes a shard from a sharded cluster. When you run removeShard, MongoDB first moves the shard’s chunks to other shards in the cluster. Then MongoDB removes the shard.
Behavior¶
Access Requirements¶
You must run removeShard while connected to a mongos. Issue the command against the admin database or use the sh._adminCommand() helper.
If you have authorization enabled, you must have the clusterManager role or any role that includes the removeShard action.
Database Migration Requirements¶
Each database in a sharded cluster has a primary shard. If the shard you want to remove is also the primary of one of the cluster’s databases, then you must manually move the databases to a new shard after migrating all data from the shard. See the movePrimary command and the Remove Shards from an Existing Sharded Cluster for more information.
Example¶
From the mongo shell, the removeShard operation resembles the following:
use admin
db.runCommand( { removeShard : "bristol01" } )
Replace bristol01 with the name of the shard to remove. When you run removeShard, the command returns immediately, with the following message:
{
"msg" : "draining started successfully",
"state" : "started",
"shard" : "bristol01",
"ok" : 1
}
The balancer begins migrating chunks from the shard named bristol01 to other shards in the cluster. These migrations happens slowly to avoid placing undue load on the overall cluster.
If you run the command again, removeShard returns the following progress output:
{
"msg" : "draining ongoing",
"state" : "ongoing",
"remaining" : {
"chunks" : 23,
"dbs" : 1
},
"ok" : 1
}
The remaining document specifies how many chunks and databases remain on the shard. Use db.printShardingStatus() to list the databases that you must move from the shard. Use the movePrimary to move databases.
After removing all chunks and databases from the shard, you can issue removeShard again see the following:
{
"msg" : "removeshard completed successfully",
"state" : "completed",
"shard" : "bristol01",
"ok" : 1
}
Thank you for your feedback!
We're sorry! You can Report a Problem to help us improve this page.