Docs Menu

範囲ベースのシャーディング

Range-based sharding involves dividing data into contiguous ranges determined by the shard key values. In this model, documents with "close" shard key values are likely to be in the same chunk or shard. This allows for efficient queries where reads target documents within a contiguous range. However, both read and write performance may decrease with poor shard key selection. See Shard Key Selection.

Diagram of the shard key value space segmented into smaller ranges or chunks.

Range-based sharding is the default sharding methodology if no other options such as those required for ハッシュされたシャーディング or zones are configured.

Ranged sharding is most efficient when the shard key displays the following traits:

The following image illustrates a sharded cluster using the field X as the shard key. If the values for X have a large range, low frequency, and change at a non-monotonic rate, the distribution of inserts may look similar to the following:

Diagram of good shard key distribution
クリックして拡大します

Use the sh.shardCollection() method, specifying the full namespace of the collection and the target index or compound index to use as the shard key.

sh.shardCollection( "database.collection", { <shard key> } )

重要

If you shard a populated collection, only one chunk is created initially. The balancer then migrates ranges from that chunk if necessary according to the configured range size.

If you shard an empty collection:

  • With no zones and zone ranges specified for the empty or non-existing collection:

    • シャーディング操作では、シャードキー値の全範囲をカバーする空のチャンクが 1 つ作成されます。

    • After the initial chunk creation, the balancer migrates the initial chunk across the shards as appropriate as well as manages the chunk distribution going forward.

  • With zones and zone ranges specified for the empty or a non-existing collections:

    • シャーディング操作では、定義されたゾーン範囲の空のチャンクと、シャードキー値の全範囲をカバーする追加のチャンクが作成され、ゾーン範囲に基づいて初期チャンク分散が実行されます。このようにチャンクを最初に作成して分散することで、ゾーン シャーディングの設定を迅速に行うことができます。

    • 初期分散後、バランサーは今後のチャンク分散を管理します。

以下も参照してください。

To learn how to deploy a sharded cluster and implement ranged sharding, see 自己管理型シャーディングされたクラスターの配置.