AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

movePrimary(データベースコマンド)

movePrimary

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:

db.adminCommand( { movePrimary: <databaseName>, to: <newPrimaryShard> } )

たとえば、次のコマンドは、プライマリシャードをtestからshard0001に移動します。

db.adminCommand( { movePrimary : "test", to : "shard0001" } )

コマンドが返すと、データベースのプライマリシャードの場所は指定されたシャードに切り替えられました。 シャードを完全に廃止するには、 removeShardコマンドを使用します。

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

警告

After starting movePrimary, do not perform any read or write operations against any unsharded collection in that database until the command completes. Read or write operations issued against those collections during the migration can result in unexpected behavior, including potential failure of the migration operation or loss of data.

このコマンドは、次の環境でホストされている配置で使用できます。

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

  • MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン

mongos uses "majority" write concern for movePrimary.

Only run movePrimary after you move unsharded collections using sh.moveCollection(). Starting in MongoDB 8.0, unmoved, unsharded collections are not available during the movePrimary process.

移動されるデータベースに MongoDB Search を使用するシャーディングされていないコレクションが含まれている場合、movePrimary が完了すると、それらの検索インデックスは使用できなくなります。movePrimary は移動したシャーディングされていないコレクションの UUID を更新するため、それらのコレクション上の MongoDB Search インデックスを手動で再構築する必要があります。

movePrimary may require a significant time to complete depending on the size of the database and factors such as network health or machine resources. During migration, attempts to write or perform any DDL operations to the unsharded collections on the database being moved fail with the error: "movePrimary is in progress".

Consider scheduling a maintenance window during which applications stop all reads and writes to the cluster. Issuing movePrimary during planned downtime mitigates the risk of encountering undefined behavior due to interleaving reads or writes to the unsharded collections in the database.

movePrimary 宛先シャードに競合するコレクション名前空間が含まれている場合、 は失敗します。 例:

  1. 管理者は、 hrデータベースのプライマリシャードを変更するためにmovePrimaryを発行します。

  2. movePrimaryがそのコレクションを移動している間に、ユーザーまたはアプリケーションがhrのシャーディングされていないコレクションに対して書込み操作を発行します。 書込み (write) 操作により、元のプライマリシャードに コレクションが作成されます。

  3. 管理者は後でmovePrimaryを発行して、 hrデータベースの元のプライマリ シャードを復元します。

  4. movePrimary インターリーブ書込み (write) 操作から残った名前空間と競合するため失敗します。

movePrimary操作の一部として、宛先シャードは、プライマリ シャードになった後、移行されたコレクションのインデックスを再構築する必要があります。 これには、コレクションあたりのインデックス数とインデックスを作成するデータ量によっては、かなりの時間が必要になる場合があります。

インデックス構築プロセスの詳細については、「入力済みコレクションでのインデックス構築 」を参照してください。

MongoDB8.0 以降、movePrimary は 変更ストリーム を持つイベント コレクションを無効化しません。コレクションが新しいシャードに移動された後も、変更ストリームはコレクションからイベントを引き続き読み取ります。

MongoDBの以前のバージョンでは、 movePrimaryはコレクション変更ストリームを無効にし、変更ストリームはコレクションからイベントを読み取れません。

すべてのMongoDBバージョンで、移動されたシャーディングされていないコレクションのUUIDをmovePrimaryが更新します。

完全な手順については、「 シャーディングされたシャードクラスタからシャードを削除する」を参照してください。

このページを評価