sh.unshardCollection
定義
sh.unshardCollection( namespace, shardID )
既存のシャーディングされたコレクションのシャーディングを解除し、コレクションデータを単一のシャードに移動します。コレクションをシャーディング解除すると、コレクションを複数のシャードに分割できなくなり、シャードキーが削除されます。
バージョン8.0の新機能。
重要
mongosh メソッド
このページでは、
mongosh
メソッドについて記載しています。ただし、データベースコマンドや Node.js などの言語固有のドライバーのドキュメントには該当しません。データベースコマンドについては、
unshardCollection
コマンドを参照してください。MongoDB API ドライバーについては、各言語の MongoDB ドライバー ドキュメントを参照してください。
The
sh.unshardCollection
method requires you to specify the shard to receive the collection data. With theunshardCollection
command, if you don't specify the destination shard, the cluster automatically selects the shard with the least data.If the collection uses zone sharding, you must first remove the range associations and shard from the zone before you unshard the collection. For more information, see シャーディングされていないゾーン.
注意
コレクションのシャーディングを解除するには 書き込み集中型の操作であり、 oplogの増加率が増加する可能性があります。 これを軽減するには、次の構成変更を検討してください。
oplogの無制限の増加を防ぐには、固定のoplogサイズを設定します。
セカンダリが古くなる可能性を減らすには、 oplogサイズを増やします。
構文
sh.unshardCollection
の構文は次のとおりです。
sh.unshardCollection( namespace, shardID )
パラメーター
Parameter | タイプ | 説明 |
---|---|---|
| string | シャーディングを解除するデータベースとコレクションを指定します。 |
| string | Specifies the recipient shard ID. As MongoDB unshards the collection, it moves the collection data from their current shards to this specific shard. |
互換性
このメソッドは、次の環境でホストされている配置で使用できます。
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです
重要
このコマンドは、共有インスタンスまたはサーバーレスインスタンスでは実行できません。 詳細については、「サポートされていないコマンド 」を参照してください。
Considerations
sh.unshardCollection()
はシャーディングされたクラスターでのみ実行できます。sh.unshardCollection()
は、シャーディングされたコレクションでのみ動作できます。sh.unshardCollection()
は一度に 1 つのコレクションに対してのみ操作できます。sh.unshardCollection()
の最小表示時間は5分です。Atlas Search インデックスは、
sh.unshardCollection()
の実行後に 再構築する必要があります 。sh.unshardCollection()
が完了するまで、シャードの追加や削除、埋め込みコンフィギュレーションサーバーと専用コンフィギュレーションサーバーの間の移行などのトポロジー変更を行うことはできません。sh.unshardCollection()
の進行中にシャーディングされていないコレクションに対して次の操作を実行することはできません。unshardCollection
の進行中は、クラスターで次の操作を実行できません。sh.unshardCollection()
の進行中に発生するインデックスビルドは、メッセージが表示されずに失敗する可能性があります。sh.unshardCollection()
の進行中は、インデックスを作成しないでください。インデックスビルドが進行中の場合は、
sh.unshardCollection()
を呼び出しないでください。
要件
コレクションのシャーディングを解除する 前に、以下の要件を満たしていることを確認してください。
アプリケーションは、影響を受けるコレクションが書込みをブロックする期間を2 秒許容できます。 書込み (write) がブロックされている期間中、アプリケーションのレイテンシが増加します。
データベースが次のリソース要件を満たしている。
コレクションを移動するシャードに、コレクションとそのインデックス用の十分なストレージ領域があることを確認します。 宛先シャードでは少なくとも
( Collection storage size + Index Size ) * 2
バイトが使用可能である必要があります。I/Oキャパシティーが50 % 未満であることを確認します。
CPU 負荷が80 % 未満であることを確認します。
動作
シャーディングされていないゾーン
ゾーンシャーディング を使用しているコレクションのシャーディングを解除するには、まずバランサーを停止し、次にゾーンから範囲とシャードを削除する必要があります。
例
コレクションのシャーディング解除
This example unshards a collection named inventory
on the
app
database to the shard02
shard.
sh.unshardCollection( "app.inventory", "shard02" )
使用可能なシャード ID のリストを取得するには、 sh.status()
を実行します。 詳細についてはsh.status() 出力 を参照してください。
ゾーンシャーディングされたコレクションのシャーディング解除
This example unshards a collection that uses zones:
バランサーを停止する
To stop the balancer, run the sh.stopBalancer()
method:
sh.stopBalancer()
範囲の関連付けを識別します。
ゾーンに関連付けられている範囲を識別するには、sh.status()
chunks
メソッドを実行し、各シャーディングされたコレクションの フィールドに範囲を確認します。
sh.status()
Remove range from zones
To remove a range from a zone, use the
sh.removeRangeFromZone()
method:
sh.removeRangeFromZone( { "app.inventory", { size: 100 }, { size: 500 } } )
コレクションで使用されるゾーンからすべての範囲を削除するまで、この手順を繰り返します。
Remove shards from zones
To remove a shard from a zone, run the
sh.removeShardFromZone()
method:
sh.removeShardFromZone( "shard01", "mid" )
Repeat until you have removed the shard from all zones.
バランサーを再起動する
To restart the balancer, run the sh.startBalancer()
method:
sh.startBalancer()