定義
sh.moveChunk(namespace, query, destination)Moves the chunk that contains the document specified by the
queryto thedestinationshard.sh.moveChunk()provides a wrapper around themoveChunkdatabase command.重要
In most circumstances, allow the balancer to automatically migrate chunks, and avoid calling
sh.moveChunk()directly.警告
このコマンドは、
moveChunkコマンドのfindオプションを使用するため、ハッシュされたシャードキーには使用できません。 ハッシュされたシャードキーを使用してチャンクを移動するには、boundsフィールドを指定するmoveChunkコマンドを使用します。重要
mongosh メソッド
This page documents a
mongoshmethod. This is not the documentation for database commands or language-specific drivers, such as Node.js.データベースコマンドについては、
moveChunkコマンドを参照してください。MongoDB API ドライバーについては、各言語の「MongoDB ドライバーのドキュメント」を参照してください。
sh.moveChunk()以下の引数を取ります。Parameterタイプ説明namespacestring
移行するチャンクを含むシャーディングされたコレクションの名前空間。
queryドキュメント
移動するチャンクを選択するシャードキーの等価一致。
destinationstring
受信者シャードのID 。
注意
listShards受信者シャードのIDを取得するには、 コマンドを使用します。デフォルトでは、チャンク内のドキュメント数が、構成されたチャンク サイズを平均ドキュメント サイズで割った結果の2倍を超える場合、MongoDB はチャンクを移動できません。
moveChunkコマンドでforceJumboオプションを指定すると、ジャンボラベルの有無にかかわらず、移動できないほど大きいチャンクの手動移行を可能にできます。 詳細については、 moveChunkコマンドを参照してください。
互換性
このメソッドは、次の環境でホストされている配置で使用できます。
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
重要
This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
例
recordsデータベースのpeopleコレクションがある場合、次の操作では、 zipcodeフィールドが53187に設定されているドキュメントを含むチャンクが検索され、そのチャンクがshard0019という名前のシャードに移動されます。
sh.moveChunk("records.people", { zipcode: "53187" }, "shard0019")