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

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

moveChunk

Internal administrative command. Moves chunks between shards. Issue the moveChunk command via a mongos instance while using the admin database. Use the following forms:

Tip

In mongosh, this command can also be run through the sh.moveChunk() helper method.

Helper methods are convenient for mongosh users, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.

db.adminCommand( { moveChunk : <namespace> ,
find : <query> ,
to : <ID of the recipient shard>,
forceJumbo: <boolean>,
_secondaryThrottle : <boolean>,
writeConcern: <document>,
_waitForDelete : <boolean> } )

あるいは、

db.adminCommand( { moveChunk : <namespace> ,
bounds : <array> ,
to : <ID of the recipient shard>,
forceJumbo: <boolean>,
_secondaryThrottle : <boolean>,
writeConcern: <document>,
_waitForDelete : <boolean> } )

注意

listShards受信者シャードのIDを取得するには、 コマンドを使用します。

The moveChunk command has the following fields:

フィールド
タイプ
説明

moveChunk

string

チャンク が存在する コレクション の 名前空間 。データベース名を含む、コレクションの完全な名前空間を指定します。

find

ドキュメント

移動するチャンクのシャードキー値を指定する、シャードキーの等価一致。 boundsフィールドとfindフィールドのいずれかを指定しますが、両方は指定しないでください。 findハッシュされたシャードキー を使用するコレクション内のチャンクを選択するために、 フィールドを使用し ない でください。

bounds

配列

移動する特定のチャンクの境界。 配列は、移動するチャンクのシャードキーの下限と上限のシャードキー値を指定する 2 つのドキュメントで構成されている必要があります。 boundsフィールドとfindフィールドのいずれかを指定しますが、両方は指定しないでください。 ハッシュされたシャードキーを使用するコレクション内のチャンクを選択するには、 boundsを使用します。

to

string

チャンクの受信者シャードのID 。

ブール値

任意。 コマンドが 移行するには大きすぎるチャンクを移動できるかどうかを決定するフラグです。 そのチャンクにはジャンボ というラベルが付いている場合と付いていない場合があります。

  • trueの場合、コマンドはチャンクを移動できます。

  • falseの場合、コマンドはチャンクを移動できません。

デフォルトは false です。

警告:

forceJumbo=true と moveChunk コマンドは、コレクションに対する書込み操作をブロックします。

このオプションを指定すると、シャードは、設定された チャンク サイズ よりも大きい場合でも、チャンクを移行します。 コレクションは、 移行中は書き込みができなくなります。

この長いブロッキング期間なしでこれらの大きなチャンクを移行するには、代わりに「サイズ制限を超えるバランス範囲」を参照してください。

_secondaryThrottle

ブール値

任意。 WiredTigerの場合、 はデフォルトでfalseになります。

  • trueの場合、デフォルトでは、チャンクの移行中に移動された各ドキュメントは、バランサーが次のドキュメントに進む前に少なくとも 1 つのセカンダリに伝播します。 これは{ w: 2 }の書込み保証 (write concern) と同等です。

    別の書込み保証 (write concern) を指定するには、 writeConcernオプションを使用します。

  • falseの場合、バランサーはセカンダリへのレプリケーションを待たずに次のドキュメントに進みます。

詳細については、「セカンダリ スロットル 」を参照してください。

writeConcern

ドキュメント

任意。 チャンクの移行中に_secondaryThrottleがセカンダリを待機するために使用する 書込み保証 ( write concern ) を表すドキュメント。

writeConcern には_secondaryThrottle: trueが必要です。

_waitForDelete

ブール値

Optional. If set to true, the delete phase of a moveChunk operation is blocking. _waitForDelete defaults to false.

_waitForDeleteフィールドが true に設定されている場合、 MongoDB は範囲削除を実行する前に orphanCleanupDelaySecs 遅延を待たなくなります。_waitForDelete パラメーターを使用しており、セカンダリで読み取り操作が発生している場合、移行の削除するフェーズによって読み取りが終了する可能性があります。詳しくは terminateSecondaryReadsOnOrphanCleanup を参照してください。

boundsの値は次の形式をとります。

[ { hashedField : <minValue> } ,
{ hashedField : <maxValue> } ]

「チャンク移行」セクションでは、MongoDB 上のシャード間でチャンクがどのように移動されるかについて説明します。

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

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

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

Only use the moveChunk in special circumstances such as preparing your sharded cluster for an initial ingestion of data, or a large bulk import operation. In most cases allow the balancer to create and balance chunks in sharded clusters. See Create Ranges in a Sharded Cluster for more information.

moveChunk requires that all indexes exist on the target (i.e. to ) shard before migration and returns an error if a required index does not exist.

moveChunk returns the following error message if another metadata operation is in progress on the chunks collection:

errmsg: "The collection's metadata lock is already taken."

If another process, such as a balancer process, changes meta data while moveChunk is running, you may see this error. You may retry the moveChunk operation without side effects.

Starting in MongoDB 5.0, you can set the maxCatchUpPercentageBeforeBlockingWrites to specify the maximum allowed percentage of data not yet migrated during a moveChunk operation when compared to the total size (in MBs) of the chunk being transferred.

このページを評価