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

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

unshardCollection

既存のシャーディングされたコレクションのシャーディングを解除し、コレクションデータを単一のシャードに移動します。コレクションをシャーディング解除すると、コレクションを複数のシャードに分割できなくなり、シャードキーが削除されます。

バージョン8.0の新機能。

Tip

In mongosh, this command can also be run through the sh.unshardCollection().

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.

このコマンドはadminデータベースで実行する必要があります。

If the collection has a zone configuration applied, you must first remove the range associations and shards from the zone before you unshard the collection. For more information, see Unshard Zones.

注意

コレクションのシャーディングを解除するには 書き込み集中型の操作であり、 oplogの増加率が増加する可能性があります。 これを軽減するには、次の構成変更を検討してください。

  • oplogの無制限の増加を防ぐには、固定のoplogサイズを設定します。

  • セカンダリが古くなる可能性を減らすには、 oplogサイズを増やします。

詳しくは、レプリカセットのoplogを参照してください。

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

  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

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

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud

注意

このタスクは、MongoDB Atlas の無料階層または Flex 階層では使用できません。

unshardCollection はQueryable Encryptionコレクションには使用できません。

db.adminCommand( {
unshardCollection: "<database>.<collection>",
toShard: "<shard-id>"
} )
フィールド
タイプ
必要性
説明

unshardCollection

string

必須

シャーディングを解除するデータベースとコレクションを指定します。

toShard

string

任意

受信者シャードIDを指定します。 MongoDBがコレクションのシャーディングを解除すると、コレクションデータは現在のシャードからこの特定のシャードに移動されます。

指定されていない場合、クラスターはデータ量が最も少ないシャードを選択します。

  • unshardCollection は、シャーディングされたクラスターでのみ実行できます。

  • unshardCollection は、シャーディングされたコレクションでのみ動作できます。

  • unshardCollection は一度に 1 つのコレクションに対してのみ操作できます。

  • unshardCollection の最小期間は5分です。

  • MongoDB Search インデックスは、unshardCollection の実行後に 再構築する必要があります 。

  • writeConcernMajorityJournalDefaultはtrueである必要があります。

  • unshardCollectionが完了するまで、シャードの追加や削除、埋め込みコンフィギュレーションサーバーと専用コンフィギュレーションサーバーの間の移行などのトポロジー変更を行うことはできません。

  • unshardCollectionの進行中にシャーディングされていないコレクションに対して次の操作を実行することはできません。

  • unshardCollectionの進行中は、クラスターで次の操作を実行できません。

  • unshardCollectionの進行中に発生するインデックスビルドは、メッセージが表示されずに失敗する可能性があります。

    • unshardCollectionの進行中は、インデックスを作成しないでください。

    • インデックスビルドが進行中の場合は、 unshardCollectionを呼び出しないでください。

  • エラーを回避するため、unshardCollection を実行するとMongoDB はコレクション内のゾーンを自動的に削除します。

  • If the collection you're unsharding uses MongoDB Search, the search index becomes unavailable when the unsharding operation completes. You need to manually rebuild the search index once the unsharding operation completes.

  • If the collection you're unsharding is archived in Atlas Online Archives, the online archive files are marked as Orphaned once the unsharding operation completes. You can create another online archive for the same database, collection, and fields as the orphaned archive as long as there is no other archive for that same combination in the Active state.

コレクションのシャーディングを解除する 前に、以下の要件を満たしていることを確認してください。

  • アプリケーションは、影響を受けるコレクションが書込みをブロックする期間を2 秒許容できます。 書込み (write) がブロックされている期間中、アプリケーションのレイテンシが増加します。

  • データベースが次のリソース要件を満たしている。

    • コレクションを移動するシャードに、コレクションとそのインデックス用の十分なストレージ領域があることを確認します。 宛先シャードでは少なくとも( Collection storage size + Index Size ) * 2バイトが使用可能である必要があります。

    • I/Oキャパシティーが50 % 未満であることを確認します。

    • CPU 負荷が80 % 未満であることを確認します。

ゾーンシャーディング を使用しているコレクションのシャーディングを解除するには、まずバランサーを停止し、次にゾーンから範囲とシャードを削除する必要があります。

次の例では、 sales.eu_accountsコレクションのシャーディングを解除します。

db.adminCommand( {
unshardCollection: "sales.eu_accounts"
} )

次の例では、 sales.us_accountsコレクションのシャーディングを解除し、そのコレクションデータをshard1に配置します。

db.adminCommand( {
unshardCollection: "sales.eu_accounts",
toShard: "shard1"
} )