For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

sh.shardDrainingStatus() (mongosh method)

sh.shardDrainingStatus(shardId)

Shows the status of a draining shard, whether the balancer is still moving chunks to other shards in the cluster or that the process is complete.

New in version 9.0.

If you don't specify shardId, the method returns the status of all shards that are currently draining.

Important

mongosh Method

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.

For the database command, see the shardDrainingStatus command.

For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.

This method is available in deployments hosted in the following environments:

Note

This command is not supported in MongoDB Atlas. See Modify your Atlas Sharded Cluster to add or remove shards from your Atlas cluster.

sh.shardDrainingStatus( <shardId> )
Parameter
Type
Description

shardId

string

Optional. Name of the draining shard to report on. If omitted, the method reports on all draining shards.

For output fields, see the shardDrainingStatus command.

If you have authorization enabled, you must have the clusterManager role or any role that includes the removeShard action.

Each database in a sharded cluster has a primary shard. If the shard you want to drain 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 a Sharded Cluster for more information.

Unsharded collections are stored on individual shards. If one of these collections is on the shard you want to remove, you must first migrate the collection to a different shard.

To migrate an unsharded collection, see the moveCollection command.

The following example returns the draining status of the shard04 shard:

sh.shardDrainingStatus( "shard04" )
{
msg: "draining ongoing",
state: "ongoing",
remaining: {
chunks: Long(2),
dbs: Long(2),
jumboChunks: Long(0),
collectionsToMove: Long(2)
},
shard: "shard04",
note: "you need to call moveCollection for collectionsToMove and afterwards movePrimary for the dbsToMove",
dbsToMove: [
"fizz",
"buzz"
],
collectionsToMove: [
"fizz.coll1",
"buzz.coll1"
],
ok: 1,
operationTime: Timestamp(1575399086, 1655),
$clusterTime: {
clusterTime: Timestamp(1575399086, 1655),
signature: {
hash: BinData(0,"XBrTmjMMe82fUtVLRm13GBVtRE8="),
keyId: Long("6766255701040824328")
}
}
}