> This page location: /docs.md > /docs/development.md > /docs/manual/sharding.md > /docs/manual/core/sharding-data-partitioning.md > /docs/manual/core/moveable-collections.md

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

# Move a Collection

Starting in MongoDB 8.0, you can move an unsharded collection to a different shard using the [`moveCollection`](https://www.mongodb.com/docs/manual/reference/command/movecollection.md#mongodb-dbcommand-dbcmd.moveCollection) command.

## About this Task

- `moveCollection` can only be run on sharded clusters.

- `moveCollection` can only move unsharded collections.

- Only one `moveCollection` operation can run at a time. You cannot run concurrent `moveCollection` operations.

- Only one of the following operations can run at a time on the cluster: [`moveCollection`](https://www.mongodb.com/docs/manual/reference/command/movecollection.md#mongodb-dbcommand-dbcmd.moveCollection), [`reshardCollection`](https://www.mongodb.com/docs/manual/reference/command/reshardcollection.md#mongodb-dbcommand-dbcmd.reshardCollection), [`rewriteCollection`](https://www.mongodb.com/docs/manual/reference/command/rewritecollection.md#mongodb-dbcommand-dbcmd.rewriteCollection), and [`unshardCollection`.](https://www.mongodb.com/docs/manual/reference/command/unshardcollection.md#mongodb-dbcommand-dbcmd.unshardCollection)

- `moveCollection` has a 5 minute minimum duration.

- [`writeConcernMajorityJournalDefault`](https://www.mongodb.com/docs/manual/reference/replica-configuration.md#mongodb-rsconf-rsconf.writeConcernMajorityJournalDefault) must be `true`.

- To move a collection that has a [uniqueness](https://www.mongodb.com/docs/manual/core/index-unique.md#std-label-index-type-unique) constraint, the new index must satisfy the [unique index requirements](https://www.mongodb.com/docs/manual/core/sharding-shard-key-indexes.md#std-label-sharding-shard-key-unique) for any existing unique indexes.

- If the collection that is being moved uses MongoDB Search, its search indexes become unavailable after `moveCollection` completes. You must manually rebuild the search indexes.

- If the collection you're moving is archived in [Atlas Online Archives](https://www.mongodb.com/docs/atlas/online-archive/manage-online-archive.md#std-label-manage-online-archive), the online archive files are marked as `Orphaned` once the moving operation completes. You can [create](https://www.mongodb.com/docs/atlas/online-archive/configure-online-archive/) another online archive for the same database, collection, and fields as the orphaned archive as long as there is no other archive for that same combination in the `Active` state.

- You cannot make topology changes, such as add or remove shard or transition between embedded and dedicated config servers, until `moveCollection` completes.

- You cannot run the following operations against the collection that is being moved while `moveCollection` is in progress:

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

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

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

  - [`db.collection.createIndexes()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.createindexes.md#mongodb-method-db.collection.createIndexes)

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

  - [`db.collection.drop()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.drop.md#mongodb-method-db.collection.drop)

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

  - [`db.collection.dropIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindex.md#mongodb-method-db.collection.dropIndex)

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

  - [`db.collection.renameCollection()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.renamecollection.md#mongodb-method-db.collection.renameCollection)

- You cannot run the following operations against the cluster while `moveCollection` is in progress:

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

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

  - [`db.createCollection()`](https://www.mongodb.com/docs/manual/reference/method/db.createcollection.md#mongodb-method-db.createCollection)

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

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

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

- Index builds that occur while `moveCollection` is in progress might silently fail.

  - Do not create indexes while `moveCollection` is in progress.

  - Do not call `moveCollection` if there are ongoing index builds.

## Access Control

If your deployment has [access control](https://www.mongodb.com/docs/manual/core/authorization.md#std-label-authorization) enabled, the [`enableSharding`](https://www.mongodb.com/docs/manual/reference/built-in-roles.md#mongodb-authrole-enableSharding) role grants you access to run the `moveCollection` command.

## Before you Begin

Before you move your collection, ensure that you meet the following requirements:

- Your application can tolerate a period of **two seconds** where the affected collection blocks writes. During the time period where writes are blocked, your application experiences an increase in latency.

- Your database meets these resource requirements:

  - Ensure the shard you are moving the collection to has enough storage space for the collection and its indexes. The destination shard requires at least `( Collection storage size + Index Size ) * 2` bytes available.

  - Ensure that your I/O capacity is below 50%.

  - Ensure that your CPU load is below 80%.

**Important:**

These requirements are not enforced by the database. A failure to allocate enough resources can result in:

- the database running out of space and shutting down

- decreased performance

- the operation taking longer than expected

If your application has time periods with less traffic, perform this operation on the collection during that time if possible.

## Steps

1. Move the collection.

   To move an unsharded collection named `inventory` on the `app` database to the `shard02` shard, run `moveCollection`:

   ```javascript
   db.adminCommand(
     {
       moveCollection: "app.inventory",
       toShard: "shard02"
     }
   )
   ```

   To get a list of the available shard IDs, run [`sh.status()`](https://www.mongodb.com/docs/manual/reference/method/sh.status.md#mongodb-method-sh.status). For details, see [sh.status() Output.](https://www.mongodb.com/docs/manual/reference/method/sh.status.md#std-label-sh-status-output-examples)

2. Monitor the progress of the moveCollection operation.

   Monitor the time remaining.

   To monitor the time remaining for the `moveCollection` operation, use the [`$currentOp`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentop.md#mongodb-pipeline-pipe.-currentOp) pipeline stage.

   This example shows how to check the progress of `moveCollection` on the `app.inventory` collection:

   ```javascript
   db.getSiblingDB("admin").aggregate( [
      { $currentOp: { allUsers: true, localOps: false } },
      {
         $match: {
         type: "op",
         "originatingCommand.reshardCollection": "app.inventory"
         }
      }
   ] )
   ```

   **Note:**

   To see updated values, you need to continuously run the preceeding pipeline.

   The [`$currentOp`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentop.md#mongodb-pipeline-pipe.-currentOp) pipeline outputs:

   - `totalOperationTimeElapsedSecs`: elapsed operation time in seconds

   - `remainingOperationTimeEstimatedSecs`: estimated time remaining in seconds for the current `moveCollection` operation. It is returned as `-1` when a new `moveCollection` operation starts.

   **Note:**

   `remainingOperationTimeEstimatedSecs` is set to a pessimistic time estimate:

   - The catch-up phase time estimate is set to the clone phase time, which

     is a relatively long time.

   - In practice, if there are only a few pending write operations, the

     actual catch-up phase time is relatively short.

   This pipeline stage has output similar to the following:

   ```javascript
   [
      {
         shard: '<shard>',
         type: 'op',
         desc: 'ReshardingRecipientService | ReshardingDonorService | ReshardingCoordinatorService <reshardingUUID>',
         op: 'command',
         ns: '<database>.<collection>',
         originatingCommand: {
         reshardCollection: '<database>.<collection>',
         key: <shardkey>,
         unique: <boolean>,
         collation: { locale: 'simple' }
         },
         totalOperationTimeElapsedSecs: <number>,
         remainingOperationTimeEstimatedSecs: <number>,
         ...
      },
      ...
   ]
   ```

   Monitor the number of bytes transferred.

   To monitor the number of bytes transferred, use [`shardingStatistics.resharding.active.bytesCopied`](https://www.mongodb.com/docs/manual/reference/command/serverstatus.md#mongodb-serverstatus-serverstatus.shardingStatistics.resharding.active.bytesCopied) and compare against the number of bytes in the collection.

3. Confirm the collection has been moved.

   To confirm the collection has been moved to the expected shard, use the [`$collStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collstats.md#mongodb-pipeline-pipe.-collStats) pipeline stage.

   This example shows how to confirm that the `app.inventory` collection exists on the expected shard:

   ```javascript
   db.inventory.aggregate( [
     { $collStats: {} },
     { $project: { "shard": 1 } }
   ] )
   ```

   This pipeline stage has output similar to the following:

   ```javascript
   [ { shard: 'shard02' } ]
   ```

## Learn More

- [Moveable Collections](https://www.mongodb.com/docs/manual/core/moveable-collections.md#std-label-moveable-collections)

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

- [`sh.moveCollection()`](https://www.mongodb.com/docs/manual/reference/method/sh.movecollection.md#mongodb-method-sh.moveCollection)
