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

# FAQ: Sharding with MongoDB

This document answers common questions about [Sharding](https://www.mongodb.com/docs/manual/sharding.md). See also the [Sharding](https://www.mongodb.com/docs/manual/sharding.md) section in the manual, which provides an [overview of sharding](https://www.mongodb.com/docs/manual/sharding.md#std-label-sharding-background), including details on:

- [Shard Keys and Considerations for Shard Key Selection](https://www.mongodb.com/docs/manual/core/sharding-shard-key.md#std-label-sharding-shard-key)

- [Query Routing](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#std-label-sharding-read-operations)

- [High Availability](https://www.mongodb.com/docs/manual/sharding.md#std-label-sharding-availability)

- [Data Partitioning with Chunks](https://www.mongodb.com/docs/manual/core/sharding-data-partitioning.md) and [Chunk Migration Process](https://www.mongodb.com/docs/manual/core/sharding-balancer-administration.md#std-label-sharding-balancing)

- [Troubleshoot Sharded Clusters](https://www.mongodb.com/docs/manual/tutorial/troubleshoot-sharded-clusters.md)

## Is sharding appropriate for a new deployment?

Sometimes. However, if your data set fits on a single server, you should begin with an unsharded deployment as sharding while your data set is small provides *little advantage* .

## Can I select a different shard key after sharding a collection?

Your options for changing a shard key depend on the version of MongoDB that you are running:

- Starting in MongoDB 5.0, you can [reshard a collection](https://www.mongodb.com/docs/manual/core/sharding-reshard-a-collection.md#std-label-sharding-resharding) by changing a document's shard key.

- You can [refine a shard key](https://www.mongodb.com/docs/manual/core/sharding-refine-a-shard-key.md#std-label-shard-key-refine) by adding a suffix field or fields to the existing shard key.

**See also:**

[Shard Keys](https://www.mongodb.com/docs/manual/core/sharding-shard-key.md)

## Why are my documents not distributed across the shards?

The balancer starts distributing data across the shards once the distribution of chunks has reached certain thresholds. See [Migration Thresholds.](https://www.mongodb.com/docs/manual/core/sharding-balancer-administration.md#std-label-sharding-migration-thresholds)

In addition, MongoDB cannot move a chunk if the number of documents in the chunk exceeds a certain number. See [Maximum Number of Documents Per Range to Migrate](https://www.mongodb.com/docs/manual/core/sharding-balancer-administration.md#std-label-migration-chunk-size-limit) and [Indivisible/Jumbo Chunks.](https://www.mongodb.com/docs/manual/core/sharding-data-partitioning.md#std-label-jumbo-chunk)

## How does `mongos` detect changes in the sharded cluster configuration?

[`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances maintain a cache of the [config database](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-config-database) that holds the metadata for the [sharded cluster.](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-sharded-cluster)

[`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) updates its cache lazily by issuing a request to a shard and discovering that its metadata is out of date. To force the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) to reload its cache, you can run the [`flushRouterConfig`](https://www.mongodb.com/docs/manual/reference/command/flushrouterconfig.md#mongodb-dbcommand-dbcmd.flushRouterConfig) command against each [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) directly.

## How does `mongos` use connections?

Each [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance maintains a pool of connections to the members of the sharded cluster. Client requests use these connections one at a time; i.e. requests are not multiplexed or pipelined.

When client requests complete, the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) returns the connection to the pool. These pools do not shrink when the number of clients decreases. This can lead to an unused [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) with a large number of open connections. If the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) is no longer in use, it is safe to restart the process to close existing connections.

To return aggregated statistics related to all of the outgoing connection pools used by the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos), connect [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh) to the [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos), and run the [`connPoolStats`](https://www.mongodb.com/docs/manual/reference/command/connpoolstats.md#mongodb-dbcommand-dbcmd.connPoolStats) command:

```bash
db.adminCommand("connPoolStats");
```

See the [System Resource Utilization](https://www.mongodb.com/docs/manual/reference/ulimit.md#std-label-system-resource-utilization) section of the [UNIX ulimit Settings for Self-Managed Deployments](https://www.mongodb.com/docs/manual/reference/ulimit.md) document.
