<section>
 <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
  Zones
  <a class="headerlink leafygreen-ui-1kepx47" href="#zones" title="Permalink to this heading">
   <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
    <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
    </path>
    <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
    </path>
   </svg>
   <div class="css-1btu0w3 evvkmar0" id="zones">
   </div>
  </a>
 </h1>
 <div class="leafygreen-ui-a5yxub">
  <p class="css-1cmx2d4 ef7gu8j0">
   On this page
  </p>
  <ul class="css-1qb0mst ef7gu8j1">
   <li class="leafygreen-ui-1e7a0ei">
    <a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#behavior-and-operations" target="_self">
     <span>
      Behavior and Operations
     </span>
    </a>
   </li>
  </ul>
 </div>
 <p class="leafygreen-ui-1kp3ins">
  In sharded clusters, you can create
  <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-zone">
   zones
  </a>
  of sharded data
based on the
  <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key">
   shard key
  </a>
  . You can associate each zone with one or
more shards in the cluster. A shard can associate with any number of
zones. In a balanced cluster, MongoDB migrates
  <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk">
   chunks
  </a>
  covered by a zone only to those shards associated with the zone.
 </p>
 <p class="leafygreen-ui-1kp3ins">
  Some common deployment patterns where zones can be applied are as follows:
 </p>
 <ul class="leafygreen-ui-rioki0">
  <li class="leafygreen-ui-d7p7b6">
   <p class="leafygreen-ui-1kp3ins">
    Isolate a specific subset of data on a specific set of shards.
   </p>
  </li>
  <li class="leafygreen-ui-d7p7b6">
   <p class="leafygreen-ui-1kp3ins">
    Ensure that the most relevant data reside on shards that are
geographically closest to the application servers.
   </p>
  </li>
  <li class="leafygreen-ui-d7p7b6">
   <p class="leafygreen-ui-1kp3ins">
    Route data to shards based on the hardware / performance of the
shard hardware.
   </p>
  </li>
 </ul>
 <p class="leafygreen-ui-1kp3ins">
  The following image illustrates a sharded cluster with three shards and two
zones. The
  <code class="leafygreen-ui-1l06pbn">
   A
  </code>
  zone represents a range with a lower boundary of
  <code class="leafygreen-ui-1l06pbn">
   1
  </code>
  and an
upper bound of
  <code class="leafygreen-ui-1l06pbn">
   10
  </code>
  . The
  <code class="leafygreen-ui-1l06pbn">
   B
  </code>
  zone represents a range with a lower boundary
of
  <code class="leafygreen-ui-1l06pbn">
   10
  </code>
  and an upper boundary of
  <code class="leafygreen-ui-1l06pbn">
   20
  </code>
  . Shards
  <code class="leafygreen-ui-1l06pbn">
   Alpha
  </code>
  and
  <code class="leafygreen-ui-1l06pbn">
   Beta
  </code>
  have
the
  <code class="leafygreen-ui-1l06pbn">
   A
  </code>
  zone. Shard
  <code class="leafygreen-ui-1l06pbn">
   Beta
  </code>
  also has the
  <code class="leafygreen-ui-1l06pbn">
   B
  </code>
  zone. Shard
  <code class="leafygreen-ui-1l06pbn">
   Charlie
  </code>
  has
no zones associated with it. The cluster is in a steady state and no chunks
violate any of the zones.
 </p>
 <div class="css-y1v7l ej97su30">
  <div role="button" tabindex="-1">
   <img alt="Diagram of data distribution based on zones in a sharded cluster" class="leafygreen-ui-1qnf57e" height="600" src="/docs/manual/images/sharded-cluster-zones.bakedsvg.svg" style="--border-color:#C1C7C6" width="1200"/>
   <div class="css-19pi7x2 ej97su31" style="--color:#444">
    click to enlarge
   </div>
  </div>
 </div>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Behavior and Operations
   <a class="headerlink leafygreen-ui-1kepx47" href="#behavior-and-operations" title="Permalink to this heading">
    <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
     <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
     </path>
     <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
     </path>
    </svg>
    <div class="css-1btu0w3 evvkmar0" id="behavior-and-operations">
    </div>
   </a>
  </h2>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Ranges
    <a class="headerlink leafygreen-ui-1kepx47" href="#ranges" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="ranges">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    Each zone covers one or more ranges of
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key">
     shard key
    </a>
    values for a
collection. Each range a zone covers is always inclusive of its lower
boundary and exclusive of its upper boundary. Zones cannot share ranges,
nor can they have overlapping ranges.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    For example, consider a shard key on
    <code class="leafygreen-ui-1l06pbn">
     {"x": 1}
    </code>
    . The cluster has
the following zone ranges:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"x\" : 5 } --&gt; { \"x\" : 10 } // Zone A\n{ \"x\" : 10} --&gt; { \"x\" : 20 } // Zone B","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-16lmvu9">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-yzcs8i">
      <pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"x"</span> <!-- -->: <span class="lg-highlight-number">5</span> } <!-- -->-<!-- -->-<!-- -->&gt; <!-- -->{ <span class="lg-highlight-string">"x"</span> <!-- -->: <span class="lg-highlight-number">10</span> } <span class="lg-highlight-comment">// Zone A</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"x"</span> <!-- -->: <span class="lg-highlight-number">10</span>} <!-- -->-<!-- -->-<!-- -->&gt; <!-- -->{ <span class="lg-highlight-string">"x"</span> <!-- -->: <span class="lg-highlight-number">20</span> } <span class="lg-highlight-comment">// Zone B</span></td></tr></tbody></table></code></pre>
      <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
       <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
        <div class="leafygreen-ui-xhlipt">
         <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
          <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
          </path>
         </svg>
        </div>
       </button>
      </div>
     </div>
    </div>
   </div>
   <ul class="leafygreen-ui-rioki0">
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      A document with a shard key value of
      <code class="leafygreen-ui-1l06pbn">
       7
      </code>
      is routed to zone A.
     </p>
    </li>
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      A document with shard key value of
      <code class="leafygreen-ui-1l06pbn">
       10
      </code>
      is routed to zone B.
     </p>
    </li>
   </ul>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Hashed Shard Keys and Zone Ranges
    <a class="headerlink leafygreen-ui-1kepx47" href="#hashed-shard-keys-and-zone-ranges" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="hashed-shard-keys-and-zone-ranges">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    For collections whose shard key includes a hashed field, zone ranges and
data distribution on that field are on hashed values. The zone contains
documents whose
    <em>
     hashed
    </em>
    shard key value falls into the defined range. A
zone range on a hashed field does not have the same predictable document
routing behavior as a zone range on an unhashed field.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    For example, consider a shard key on
    <code class="leafygreen-ui-1l06pbn">
     {"x" : "hashed"}
    </code>
    . The following
range represents the
    <em>
     hashed
    </em>
    range between
    <code class="leafygreen-ui-1l06pbn">
     5
    </code>
    and
    <code class="leafygreen-ui-1l06pbn">
     10
    </code>
    :
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"x\": NumberLong(\"4470791281878691347\") } --&gt; { \"x\": NumberLong(\"7766103514953448109\") } // Zone A","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-16lmvu9">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-1b1bvay">
      <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"x"</span>: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"4470791281878691347"</span>) } <!-- -->-<!-- -->-<!-- -->&gt; <!-- -->{ <span class="lg-highlight-string">"x"</span>: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"7766103514953448109"</span>) } <span class="lg-highlight-comment">// Zone A</span></td></tr></tbody></table></code></pre>
      <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
       <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
        <div class="leafygreen-ui-xhlipt">
         <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
          <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
          </path>
         </svg>
        </div>
       </button>
      </div>
     </div>
    </div>
   </div>
   <ul class="leafygreen-ui-rioki0">
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      A document with a shard key value of
      <code class="leafygreen-ui-1l06pbn">
       1
      </code>
      is routed to Zone A
since the
      <em>
       hashed
      </em>
      value of
      <code class="leafygreen-ui-1l06pbn">
       1
      </code>
      falls into the defined range.
     </p>
    </li>
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      A document with a shard key value of
      <code class="leafygreen-ui-1l06pbn">
       15
      </code>
      is routed to Zone A
since the
      <em>
       hashed
      </em>
      value of
      <code class="leafygreen-ui-1l06pbn">
       15
      </code>
      falls into the defined range.
     </p>
    </li>
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      A document with a shard key value of
      <code class="leafygreen-ui-1l06pbn">
       8
      </code>
      is not routed to
Zone A since the
      <em>
       hashed
      </em>
      value of
      <code class="leafygreen-ui-1l06pbn">
       8
      </code>
      does not fall into the
defined range.
     </p>
    </li>
   </ul>
   <p class="leafygreen-ui-1kp3ins">
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
     <span>
      <code class="leafygreen-ui-1l06pbn">
       mongosh
      </code>
     </span>
    </a>
    provides the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/convertShardKeyToHashed/#mongodb-method-convertShardKeyToHashed">
     <code class="leafygreen-ui-1l06pbn">
      convertShardKeyToHashed()
     </code>
    </a>
    for computing the post-hash value of
the specified parameter.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    One valid use of zone ranges on a hashed field is to restrict the data
for a collection to the shard or shards in a single zone. Create a zone
range that covers the entire range of possible hashed shard key values
using
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-MinKey">
     <code class="leafygreen-ui-1l06pbn">
      MinKey
     </code>
    </a>
    as the lower bound and
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-MaxKey">
     <code class="leafygreen-ui-1l06pbn">
      MaxKey
     </code>
    </a>
    as the upper bound.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    To define ranges, MongoDB provides the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/updateZoneKeyRange/#mongodb-dbcommand-dbcmd.updateZoneKeyRange">
     <code class="leafygreen-ui-1l06pbn">
      updateZoneKeyRange
     </code>
    </a>
    command and the associated helper methods
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#mongodb-method-sh.updateZoneKeyRange">
     <code class="leafygreen-ui-1l06pbn">
      sh.updateZoneKeyRange()
     </code>
    </a>
    and
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addShardTag/#mongodb-method-sh.addShardTag">
     <code class="leafygreen-ui-1l06pbn">
      sh.addShardTag()
     </code>
     .
    </a>
   </p>
   <p class="leafygreen-ui-1kp3ins">
    You can run
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/updateZoneKeyRange/#mongodb-dbcommand-dbcmd.updateZoneKeyRange">
     <code class="leafygreen-ui-1l06pbn">
      updateZoneKeyRange
     </code>
    </a>
    database command and its helpers
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#mongodb-method-sh.updateZoneKeyRange">
     <code class="leafygreen-ui-1l06pbn">
      sh.updateZoneKeyRange()
     </code>
    </a>
    and
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addTagRange/#mongodb-method-sh.addTagRange">
     <code class="leafygreen-ui-1l06pbn">
      sh.addTagRange()
     </code>
    </a>
    on
an unsharded collection or a non-existing collection.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    Dropping a collection deletes its associated zone/tag ranges.
   </p>
   <span class="leafygreen-ui-1qnjd6d" id="std-label-zone-sharding-initial-chunk-distribution">
   </span>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Initial Chunk Distribution
    <a class="headerlink leafygreen-ui-1kepx47" href="#initial-chunk-distribution" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="initial-chunk-distribution">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    By defining the zones and the zone ranges
    <em>
     before
    </em>
    sharding an empty
or a non-existing collection, the shard collection operation creates
chunks for the defined zone ranges as well as any additional chunks
to cover the entire range of the shard key values and performs an
initial chunk distribution based on the zone ranges. This initial
creation and distribution of chunks allows for faster setup of zoned
sharding. After the initial distribution, the balancer manages the
chunk distribution going forward.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    MongoDB supports sharding collections on
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/create/#std-label-index-type-compound-hashed">
     compound hashed indexes
    </a>
    . When
sharding an empty or non-existing collection using a compound hashed
shard key, additional requirements apply in order for MongoDB to
perform initial chunk creation and distribution.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    See
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#std-label-pre-define-zone-range-hashed-example">
     Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection
    </a>
    for for an example.
   </p>
   <div class="leafygreen-ui-13vw3ie" role="note">
    <h2 class="leafygreen-ui-1fn4p2b">
     Tip
    </h2>
    <h3 class="leafygreen-ui-144d5kf">
     <strong>
      See also:
     </strong>
    </h3>
    <div class="leafygreen-ui-9mycqc">
     <p class="leafygreen-ui-1kp3ins">
      <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.balancerCollectionStatus/#mongodb-method-sh.balancerCollectionStatus">
       <code class="leafygreen-ui-1l06pbn">
        sh.balancerCollectionStatus()
       </code>
      </a>
     </p>
    </div>
   </div>
   <span class="leafygreen-ui-1qnjd6d" id="std-label-zone-sharding-balancer">
   </span>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Balancer
    <a class="headerlink leafygreen-ui-1kepx47" href="#balancer" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="balancer">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    The
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-balancer">
     balancer
    </a>
    attempts to evenly distribute a sharded collection's
chunks across all shards in the cluster.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    For each
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk">
     chunk
    </a>
    marked for migration, the balancer checks each
possible destination shard for any configured zones. If the chunk range falls
into a zone, the balancer migrates the chunk into a shard inside that
zone. Chunks that do not fall into a zone can exist on
    <em>
     any
    </em>
    shard in the
cluster and are migrated normally.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    During balancing rounds, if the balancer detects that any chunks violate the
configured zones for a given shard, the balancer migrates those chunks to
a shard where no conflict exists.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    After associating a zone with a shard or shards and configuring the
zone with a shard key range for a sharded collection, the cluster may
take some time to migrate the affected data for the sharded collection.
This depends on the division of chunks and the current distribution of
data in the cluster. When balancing is complete, reads and writes for
documents in a given zone are routed only to the shard or shards inside
that zone.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    Once configured, the balancer respects zones during future
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-internals-balancing">
     balancing rounds
     <!-- -->
     .
    </a>
   </p>
   <div class="leafygreen-ui-13vw3ie" role="note">
    <h2 class="leafygreen-ui-1fn4p2b">
     Tip
    </h2>
    <h3 class="leafygreen-ui-144d5kf">
     <strong>
      See also:
     </strong>
    </h3>
    <div class="leafygreen-ui-9mycqc">
     <p class="leafygreen-ui-1kp3ins">
      <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.balancerCollectionStatus/#mongodb-method-sh.balancerCollectionStatus">
       <code class="leafygreen-ui-1l06pbn">
        sh.balancerCollectionStatus()
       </code>
      </a>
     </p>
    </div>
   </div>
   <span class="leafygreen-ui-1qnjd6d" id="std-label-zone-sharding-shard-key">
   </span>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Shard Key
    <a class="headerlink leafygreen-ui-1kepx47" href="#shard-key" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="shard-key">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    You must use fields contained in the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key">
     shard key
    </a>
    when defining a new
range for a zone to cover. If using a
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-compound-index">
     compound
    </a>
    shard
key, the range must include the prefix of the shard key.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    For example, given a shard key
    <code class="leafygreen-ui-1l06pbn">
     { a : 1, b : 1, c : 1 }
    </code>
    , creating or
updating a range to cover values of
    <code class="leafygreen-ui-1l06pbn">
     b
    </code>
    requires including
    <code class="leafygreen-ui-1l06pbn">
     a
    </code>
    as the
prefix. Creating or updating a range to covers values of
    <code class="leafygreen-ui-1l06pbn">
     c
    </code>
    requires
including
    <code class="leafygreen-ui-1l06pbn">
     a
    </code>
    and
    <code class="leafygreen-ui-1l06pbn">
     b
    </code>
    as the prefix.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    You cannot create ranges using fields not included in the shard key. For
example, if you wanted to use zones to partition data based on
geographic location, the shard key would need the first field to
contain geographic data.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    When choosing a shard key for a collection, consider what fields you might
want to use for configuring zones. See
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-sharding-internals-choose-shard-key">
     Choose a Shard Key
    </a>
    for considerations in choosing a shard key.
   </p>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Shard Zone Boundaries
    <a class="headerlink leafygreen-ui-1kepx47" href="#shard-zone-boundaries" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="shard-zone-boundaries">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    Zone ranges are always inclusive of the lower boundary and exclusive
of the upper boundary.
   </p>
   <div class="leafygreen-ui-13vw3ie" role="note">
    <h2 class="leafygreen-ui-1fn4p2b">
     Tip
    </h2>
    <h3 class="leafygreen-ui-144d5kf">
     <strong>
      See also:
     </strong>
    </h3>
    <div class="leafygreen-ui-9mycqc">
     <p class="leafygreen-ui-1kp3ins">
      <a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-shard-zone/">
       Manage Shard Zones
      </a>
     </p>
    </div>
   </div>
  </section>
 </section>
</section>
