> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

# startShardDraining (database command)

## Definition

Starts the process of draining chunks from a shard to prepare it for removal from a sharded cluster.

When the command runs, it tells the balancer that you want to drain the given shard. Asynchronously, the balancer then begins moving chunks from the shard to other shards in the cluster. When the balancer completes this process, the shard contains no data and can be safely removed from the cluster.

**Note:**

The balancer must be enabled for `startShardDraining` to move chunks off the shard. If the balancer is disabled, no chunks are migrated and [`shardDrainingStatus`](https://www.mongodb.com/docs/manual/reference/command/sharddrainingstatus.md#mongodb-dbcommand-dbcmd.shardDrainingStatus) continues to report remaining work on the shard.

The command returns an error if the shard doesn't exist, otherwise it returns `ok`.

To check the status of a draining shard, use the [`shardDrainingStatus`](https://www.mongodb.com/docs/manual/reference/command/sharddrainingstatus.md#mongodb-dbcommand-dbcmd.shardDrainingStatus) command.

To stop draiing a shard, see the [`stopShardDraining`](https://www.mongodb.com/docs/manual/reference/command/stopsharddraining.md#mongodb-dbcommand-dbcmd.stopShardDraining) command.

To remove a drained shard, see the [`commitShardRemoval`](https://www.mongodb.com/docs/manual/reference/command/commitshardremoval.md#mongodb-dbcommand-dbcmd.commitShardRemoval) command.

**New in version 8.3**

## Compatibility

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

- [MongoDB Enterprise](https://www.mongodb.com/docs/manual/administration/install-enterprise.md#std-label-install-mdb-enterprise): The subscription-based, self-managed version of MongoDB

- [MongoDB Community](https://www.mongodb.com/docs/manual/administration/install-community.md#std-label-install-mdb-community-edition): The source-available, free-to-use, and self-managed version of MongoDB

**Note:**

This command is not supported in [MongoDB Atlas](https://www.mongodb.com/docs/atlas). See [Modify your Atlas Sharded Cluster](https://www.mongodb.com/docs/atlas/scale-cluster/#modify-the-number-of-shards) to add or remove shards from your Atlas cluster.

## Syntax

The command has the following syntax:

```javascript
db.adminCommand( {
     startShardDraining: <shardToDrain>
} )
```

## Behavior

### Access Requirements

If you have [`authorization`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-security.authorization) enabled, you must have the [`clusterManager`](https://www.mongodb.com/docs/manual/reference/built-in-roles.md#mongodb-authrole-clusterManager) role or any role that includes the [`removeShard`](https://www.mongodb.com/docs/manual/reference/privilege-actions.md#mongodb-authaction-removeShard) action.

### No Cluster Back Ups During Shard Drain

You cannot back up the cluster while draining the shard.

### Concurrent Drain Shard Operations

You can have more than one shard draining operation in progress at a time.

### Database Migration Requirements

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`](https://www.mongodb.com/docs/manual/reference/command/moveprimary.md#mongodb-dbcommand-dbcmd.movePrimary) command and the [Remove Shards from a Sharded Cluster](https://www.mongodb.com/docs/manual/tutorial/remove-shards-from-cluster.md#std-label-remove-shards-from-cluster-tutorial) for more information.

### Collection Migration Requirements

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`](https://www.mongodb.com/docs/manual/reference/command/movecollection.md#mongodb-dbcommand-dbcmd.moveCollection) command.

### Chunk Balancing

When you drain a shard in a cluster with an uneven chunk distribution, the balancer first removes the chunks from the draining shard and then balances the remaining uneven chunk distribution.

**See also:**

[`balancerCollectionStatus`](https://www.mongodb.com/docs/manual/reference/command/balancercollectionstatus.md#mongodb-dbcommand-dbcmd.balancerCollectionStatus)

### Write Concern

[`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#std-program-mongos) converts the [write concern](https://www.mongodb.com/docs/manual/reference/write-concern.md#std-label-write-concern) of the `startShardDraining` command to [`"majority"`.](https://www.mongodb.com/docs/manual/reference/write-concern.md#mongodb-writeconcern-writeconcern.-majority-)

### Change Streams

Draining a shard may cause an open [change stream cursor](https://www.mongodb.com/docs/manual/changestreams.md#std-label-changeStreams) to close, and the closed change stream cursor may not be fully resumable.

### DDL Operations

If you run `startShardDraining` while your cluster is executing a DDL operation (operation that modifies a collection such as [`reshardCollection`](https://www.mongodb.com/docs/manual/reference/command/reshardcollection.md#mongodb-dbcommand-dbcmd.reshardCollection)), the shard draining only executes after the concurrent DDL operation finishes.

## Examples

To start draining a shard, use the [`db.adminCommand()`](https://www.mongodb.com/docs/manual/reference/method/db.admincommand.md#mongodb-method-db.adminCommand) method:

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

## Learn More

- [Remove Shards from a Sharded Cluster](https://www.mongodb.com/docs/manual/tutorial/remove-shards-from-cluster.md#std-label-remove-shards-from-cluster-tutorial)

- [`shardDrainingStatus`](https://www.mongodb.com/docs/manual/reference/command/sharddrainingstatus.md#mongodb-dbcommand-dbcmd.shardDrainingStatus)

- [`commitShardRemoval`](https://www.mongodb.com/docs/manual/reference/command/commitshardremoval.md#mongodb-dbcommand-dbcmd.commitShardRemoval)

- [`stopShardDraining`](https://www.mongodb.com/docs/manual/reference/command/stopsharddraining.md#mongodb-dbcommand-dbcmd.stopShardDraining)
