- Reference >
- Database Commands >
- Sharding Commands >
- movePrimary
movePrimary¶
On this page
-
movePrimary
¶ In a sharded cluster, this command reassigns the database’s primary shard, which holds all un-sharded collections in the database.
movePrimary
is an administrative command that is only available formongos
instances. Only usemovePrimary
when removing a shard from a sharded cluster.movePrimary
changes the primary shard for a database in the cluster metadata, and migrates all un-sharded collections to the specified shard. Use the command with the following form:When the command returns, the database’s primary location will shift to the designated shard. To fully decommission a shard, use the
removeShard
command.
Considerations¶
Limitations¶
Only use movePrimary
when:
- the database does not contain any collections, or
- you have drained all sharded collections using the
removeShard
command.
Use¶
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.