Docs Menu
Docs Home
/ /

shardDrainingStatus (database command)

shardDrainingStatus

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.

The command returns an error if the shard doesn't exist, otherwise it returns the status of the draining operation.

To start draining a shard, see the startShardDraining command.

New in version 8.3.

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

  • MongoDB Enterprise: The subscription-based, self-managed version of MongoDB

  • MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB

Note

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

The command has the following syntax:

db.adminCommand( {
shardDrainingStatus: <shard>
} )

This command returns the following output:

Field
Type
Description

msg

string

Provides the current draining operation being performed by the balancer.

state

string

Provides the status of the draining operation.

shard

string

Indicates the draining shard.

remaining

document

Shows the remaining tasks the balancer must perform to drain the shard.

remaining.chunks

long

Indicates the number of chunks still on the shard.

remaining.dbs

long

Indicates the number of databases still on the shard.

remaining.jumboChunks

long

Indicates the number of large chunks still on the shard.

remaining.collectionsToMove

long

Indicates the number of collections still on the shard.

note

string

Provides additional message for the user.

dbsToMove

array

Indicates databases that use the draining shard as the primary shard. Before you can remove the shard from the cluster, you must manually move these databases to a new shard using the movePrimary command.

collectionsToMove

array

Indicates unsharded collections stored on the draining shard. Before you can remove the shard from the cluster, you must manually move these collections to another shard using the moveCollection 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.

To start draining a shard, use the db.adminCommand() method to run the startShardDraining command:

db.adminCommand( { startShardDraining: "shard04" } )

To check the status of the draining operation, use the shardDrainingStatus command:

db.adminCommand( { 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")
}
}
}

Back

shardCollection

On this page