This version of the documentation is archived and no longer supported.



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 for mongos instances. Only use movePrimary when removing a shard from a sharded cluster.


Only use movePrimary when:

  • the database does not contain any collections with data, or
  • you have drained all sharded collections using the removeShard command.

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

movePrimary changes the primary shard for this database in the cluster metadata, and 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.