In a sharded cluster, movePrimary reassigns the primary shard which holds all un-sharded collections in the database. movePrimary first changes the primary shard in the cluster metadata, and then migrates all un-sharded collections to the specified shard. Use the command with the following form:

{ movePrimary : "test", to : "shard0001" }

When the command returns, the database’s primary location will shift to the designated shard. To fully decommission a shard, use the removeShard command.

movePrimary is an administrative command that is only available for mongos instances.



Avoid accessing an un-sharded collection during migration. movePrimary does not prevent reading and writing during its operation, and such actions yield undefined behavior.

movePrimary may take significant time to complete, and you should plan for this unavailability.

movePrimary will fail if the destination shard contains a conflicting collection name. This may occur if documents are written to an un-sharded collection while the collection is moved away, and later the original primary shard is restored.


If you use the movePrimary command to move un-sharded collections, you must either restart all mongos instances, or use the flushRouterConfig command on all mongos instances before writing any data to the cluster. This action notifies the mongos of the new shard for the database.

If you do not update the mongos instances’ metadata cache after using movePrimary, the mongos may not write data to the correct shard. To recover, you must manually intervene.

Additional Information

See Remove Shards from an Existing Sharded Cluster for a complete procedure.

←   moveChunk isdbgrid  →

Was this page helpful?

Yes No

Thank you for your feedback!

We're sorry! You can Report a Problem to help us improve this page.