<section>
 <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
  sh.updateZoneKeyRange()
  <a class="headerlink leafygreen-ui-1kepx47" href="#sh.updatezonekeyrange--" 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="sh.updatezonekeyrange--">
   </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="#definition" target="_self">
     <span>
      Definition
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#compatibility" target="_self">
     <span>
      Compatibility
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#behavior" target="_self">
     <span>
      Behavior
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
     <span>
      Examples
     </span>
    </a>
   </li>
  </ul>
 </div>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Definition
   <a class="headerlink leafygreen-ui-1kepx47" href="#definition" 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="definition">
    </div>
   </a>
  </h2>
  <dl class="method">
   <dt>
    <code class="leafygreen-ui-1l06pbn">
     sh.updateZoneKeyRange(namespace, minimum, maximum, zone)
    </code>
    <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-sh.updateZoneKeyRange" title="Permalink to this definition">
     <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="mongodb-method-sh.updateZoneKeyRange">
     </div>
    </a>
   </dt>
   <dd>
    <p class="leafygreen-ui-1kp3ins">
     Associates a range of shard key values with a
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-zone">
      zone
      <!-- -->
      .
     </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="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.updateZoneKeyRange" target="_self">
      <span>
       <code class="leafygreen-ui-1l06pbn">
        sh.updateZoneKeyRange()
       </code>
      </span>
     </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>
    <div class="leafygreen-ui-85da11" role="note">
     <h2 class="leafygreen-ui-1ac4g5h">
      Important
     </h2>
     <h3 class="leafygreen-ui-144d5kf">
      <strong>
       mongosh Method
      </strong>
     </h3>
     <div class="leafygreen-ui-9mycqc">
      <p class="leafygreen-ui-1kp3ins">
       This page documents a
       <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>
       method. This is
       <em>
        not
       </em>
       the documentation for database commands or language-specific drivers,
such as Node.js.
      </p>
      <p class="leafygreen-ui-1kp3ins">
       For the database command, see 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
       <!-- -->
       .
      </p>
      <p class="leafygreen-ui-1kp3ins">
       For MongoDB API drivers, refer to the language-specific
       <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
        <span>
         MongoDB driver documentation
         <!-- -->
         .
        </span>
       </a>
      </p>
     </div>
    </div>
    <p class="leafygreen-ui-1kp3ins">
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.updateZoneKeyRange" target="_self">
      <span>
       <code class="leafygreen-ui-1l06pbn">
        sh.updateZoneKeyRange()
       </code>
      </span>
     </a>
     takes the following arguments:
    </p>
    <div class="leafygreen-ui-skkc39" tabindex="0">
     <table class="leafygreen-ui-hr8lsv">
      <colgroup>
       <col style="width:20%"/>
       <col style="width:20%"/>
       <col style="width:80%"/>
      </colgroup>
      <thead class="leafygreen-ui-a9ho40">
       <tr data-testid="leafygreen-ui-header-row">
        <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
         <div class="leafygreen-ui-ui0te9">
          <div>
           Parameter
          </div>
         </div>
        </th>
        <th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
         <div class="leafygreen-ui-ui0te9">
          <div>
           Type
          </div>
         </div>
        </th>
        <th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
         <div class="leafygreen-ui-ui0te9">
          <div>
           Description
          </div>
         </div>
        </th>
       </tr>
      </thead>
      <tbody>
       <tr class="">
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           <code class="leafygreen-ui-1l06pbn">
            namespace
           </code>
          </div>
         </div>
        </td>
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           string
          </div>
         </div>
        </td>
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           <p class="leafygreen-ui-1kp3ins">
            The
            <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-namespace">
             namespace
            </a>
            of the sharded collection associate with the
            <code class="leafygreen-ui-1l06pbn">
             zone
            </code>
            .
           </p>
           <p class="leafygreen-ui-1kp3ins">
            The collection must be sharded for the operation to succeed.
           </p>
          </div>
         </div>
        </td>
       </tr>
       <tr class="">
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           <code class="leafygreen-ui-1l06pbn">
            minimum
           </code>
          </div>
         </div>
        </td>
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           document
          </div>
         </div>
        </td>
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           <p class="leafygreen-ui-1kp3ins">
            The inclusive lower bound of the range of
            <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key">
             shard key
            </a>
            values.
           </p>
           <p class="leafygreen-ui-1kp3ins">
            Specify each field of the shard key in the form of
            <code class="leafygreen-ui-1l06pbn">
             &lt;fieldname&gt; : &lt;value&gt;
            </code>
            .
The value must be of the same BSON type or types as the shard key.
           </p>
           <p class="leafygreen-ui-1kp3ins">
            To use hashed sharding, the field value needs to be of type
            <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json-v1/#mongodb-bsontype-data_numberlong">
             <code class="leafygreen-ui-1l06pbn">
              NumberLong
             </code>
             .
            </a>
           </p>
          </div>
         </div>
        </td>
       </tr>
       <tr class="">
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           <code class="leafygreen-ui-1l06pbn">
            maximum
           </code>
          </div>
         </div>
        </td>
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           document
          </div>
         </div>
        </td>
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           <p class="leafygreen-ui-1kp3ins">
            The exclusive upper bound of the range of
            <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key">
             shard key
            </a>
            values.
           </p>
           <p class="leafygreen-ui-1kp3ins">
            Specify each field of the shard key in the form of
            <code class="leafygreen-ui-1l06pbn">
             &lt;fieldname&gt; : &lt;value&gt;
            </code>
            .
The value must be of the same BSON type or types as the shard key.
           </p>
           <p class="leafygreen-ui-1kp3ins">
            To use hashed sharding, the field value needs to be of type
            <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json-v1/#mongodb-bsontype-data_numberlong">
             <code class="leafygreen-ui-1l06pbn">
              NumberLong
             </code>
             .
            </a>
           </p>
          </div>
         </div>
        </td>
       </tr>
       <tr class="">
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           <code class="leafygreen-ui-1l06pbn">
            zone
           </code>
          </div>
         </div>
        </td>
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           string
          </div>
         </div>
        </td>
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           The name of the zone to associate with the range of shard key values bounded
by
           <code class="leafygreen-ui-1l06pbn">
            minimum
           </code>
           and
           <code class="leafygreen-ui-1l06pbn">
            maximum
           </code>
           .
          </div>
         </div>
        </td>
       </tr>
      </tbody>
     </table>
    </div>
    <p class="leafygreen-ui-1kp3ins">
     Only issue
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.updateZoneKeyRange" target="_self">
      <span>
       <code class="leafygreen-ui-1l06pbn">
        sh.updateZoneKeyRange()
       </code>
      </span>
     </a>
     when connected to a
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
      <code class="leafygreen-ui-1l06pbn">
       mongos
      </code>
     </a>
     instance.
    </p>
   </dd>
  </dl>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Compatibility
   <a class="headerlink leafygreen-ui-1kepx47" href="#compatibility" 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="compatibility">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   This method is available in deployments hosted in the following environments:
  </p>
  <ul class="leafygreen-ui-rioki0">
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas?tck=docs_server" target="_self">
      <span>
       MongoDB Atlas
      </span>
     </a>
     : The fully
managed service for MongoDB deployments in the cloud
    </p>
   </li>
  </ul>
  <div class="leafygreen-ui-85da11" role="note">
   <h2 class="leafygreen-ui-1ac4g5h">
    Important
   </h2>
   <div class="leafygreen-ui-9mycqc">
    <p class="leafygreen-ui-1kp3ins">
     This command is not supported in serverless instances.
For more information, see
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/" target="_self">
      <span>
       Unsupported Commands
       <!-- -->
       .
      </span>
     </a>
    </p>
   </div>
  </div>
  <ul class="leafygreen-ui-rioki0">
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise/#std-label-install-mdb-enterprise">
      MongoDB Enterprise
     </a>
     : The
subscription-based, self-managed version of MongoDB
    </p>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-community/#std-label-install-mdb-community-edition">
      MongoDB Community
     </a>
     : The
source-available, free-to-use, and self-managed version of MongoDB
    </p>
   </li>
  </ul>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Behavior
   <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" 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">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   You cannot create a range of shard key values whose lower and upper boundaries
overlap with an existing range for the sharded collection. For example, given
an existing range of
   <code class="leafygreen-ui-1l06pbn">
    1
   </code>
   to
   <code class="leafygreen-ui-1l06pbn">
    10
   </code>
   , you cannot create a new range of
   <code class="leafygreen-ui-1l06pbn">
    5
   </code>
   to
   <code class="leafygreen-ui-1l06pbn">
    20
   </code>
   , as the new range would overlap with the existing range.
  </p>
  <p class="leafygreen-ui-1kp3ins">
   A zone can have multiple ranges of data associated with it, but a range
can at most be associated with a single zone.
  </p>
  <p class="leafygreen-ui-1kp3ins">
   See the
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding">
    zone
   </a>
   manual page for more information on zones
in sharded clusters.
  </p>
  <span class="leafygreen-ui-1qnjd6d" id="std-label-updateZoneKeyRange-method-init-chunk-distribution">
  </span>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Initial Chunk Distribution for Empty or Non-Existing Collections
    <a class="headerlink leafygreen-ui-1kepx47" href="#initial-chunk-distribution-for-empty-or-non-existing-collections" 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-for-empty-or-non-existing-collections">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    If you are considering performing
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding">
     zone sharding
    </a>
    on an empty or non-existent collection, use
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.updateZoneKeyRange" target="_self">
     <span>
      <code class="leafygreen-ui-1l06pbn">
       sh.updateZoneKeyRange()
      </code>
     </span>
    </a>
    to create the zones and zone ranges
    <em>
     before
    </em>
    sharding the collection (
    <em>
     since 4.0.2
    </em>
    ). Starting in version
4.0.3, creating zones and zone ranges on empty or non-existing
collections allows MongoDB to optimize the initial chunk creation and
distribution process when sharding the collection. This optimized
process supports faster setup of zoned sharding with less balancer
overhead than creating zones after sharding. The
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-balancing">
     balancer
    </a>
    performs all chunk management after the optimized
initial chunk creation and distribution.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    For an example of defining zones and zone ranges for initial chunk
distribution, see
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-pre-define-zone-range-example" target="_self">
     <span>
      Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection
      <!-- -->
      .
     </span>
    </a>
   </p>
   <span class="leafygreen-ui-1qnjd6d" id="std-label-updateZoneKeyRange-method-init-chunk-distribution-compound-hashed">
   </span>
   <section>
    <h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
     Initial Chunk Distribution with Compound Hashed Shard Keys
     <a class="headerlink leafygreen-ui-1kepx47" href="#initial-chunk-distribution-with-compound-hashed-shard-keys" 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-with-compound-hashed-shard-keys">
      </div>
     </a>
    </h4>
    <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>
     . MongoDB can
perform optimized initial chunk creation and distribution when sharding
the empty or non-existing collection on a compound hashed shard key.
    </p>
    <div aria-hidden="true">
    </div>
    <div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs">
     <div class="leafygreen-ui-jp7pox" id="tabs-10">
      <div aria-label="Tabs to describe usage of hash-not-prefix/hash-prefix" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
       <button aria-controls="_ajs5h4gl0" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_ae4tdrh82" name="" role="tab" tabindex="0">
        <div class="leafygreen-ui-1nxuzmg">
         Hashed Field Is Prefix
        </div>
       </button>
       <button aria-controls="_d8htp6w2p" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_stw53wc51" name="" role="tab" tabindex="-1">
        <div class="leafygreen-ui-1nxuzmg">
         Hashed Field is Not Prefix
        </div>
       </button>
      </div>
      <div class="leafygreen-ui-ov1ktg">
       <div class="leafygreen-ui-1sg2lsz">
       </div>
      </div>
     </div>
     <div class="lg-ui-tab-panels-0000" data-lgid="lg-tabs-tab_panels">
      <div>
       <div aria-labelledby="_3l32fqowp" class="" id="_4pgl196ao" role="tabpanel">
        <div class="leafygreen-ui-1kdmo88">
         <p class="leafygreen-ui-1kp3ins">
          If the hashed field is the prefix of the shard key (i.e. the first
field in the shard key), all of the following must be true for
MongoDB to perform initial chunk creation and distribution:
         </p>
         <ul class="leafygreen-ui-rioki0">
          <li class="leafygreen-ui-d7p7b6">
           <p class="leafygreen-ui-1kp3ins">
            The collection has a single zone range with
            <code class="leafygreen-ui-1l06pbn">
             MinKey
            </code>
            for
all lower-bound fields and
            <code class="leafygreen-ui-1l06pbn">
             MaxKey
            </code>
            for all upper-bound
fields.
           </p>
          </li>
          <li class="leafygreen-ui-d7p7b6">
           <p class="leafygreen-ui-1kp3ins">
            <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection">
             <code class="leafygreen-ui-1l06pbn">
              sh.shardCollection()
             </code>
            </a>
            specifies the
            <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#std-label-method-shard-collection-presplitHashedZones">
             presplitHashedZones: true
            </a>
            option.
           </p>
          </li>
         </ul>
        </div>
       </div>
      </div>
      <div>
       <div aria-labelledby="_vuery2y52" class="leafygreen-ui-38lglc" id="_zwxtjhg3c" role="tabpanel">
        <div class="leafygreen-ui-1kdmo88">
         <p class="leafygreen-ui-1kp3ins">
          If the hashed field is
          <em>
           not
          </em>
          the prefix of the shard key (i.e.
the shard key has one or more non-hashed leading fields), all of
the following must be true for MongoDB to perform initial chunk
creation and distribution:
         </p>
         <ul class="leafygreen-ui-rioki0">
          <li class="leafygreen-ui-d7p7b6">
           <p class="leafygreen-ui-1kp3ins">
            The collection has one zone range for each combination of distinct
prefix field values (i.e. all fields preceding the hashed field).
           </p>
          </li>
          <li class="leafygreen-ui-d7p7b6">
           <p class="leafygreen-ui-1kp3ins">
            For the lower-bound of each zone range, specify
            <code class="leafygreen-ui-1l06pbn">
             MinKey
            </code>
            for
the hashed field and all subsequent fields.
           </p>
          </li>
          <li class="leafygreen-ui-d7p7b6">
           <p class="leafygreen-ui-1kp3ins">
            For each zone range, at least one upper-bound prefix field
            <em>
             must
            </em>
            differ from its lower-bound counterpart.
           </p>
          </li>
          <li class="leafygreen-ui-d7p7b6">
           <p class="leafygreen-ui-1kp3ins">
            <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection">
             <code class="leafygreen-ui-1l06pbn">
              sh.shardCollection()
             </code>
            </a>
            specifies the
            <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#std-label-method-shard-collection-presplitHashedZones">
             presplitHashedZones: true
            </a>
            option.
           </p>
          </li>
         </ul>
        </div>
       </div>
      </div>
     </div>
    </div>
    <p class="leafygreen-ui-1kp3ins">
     For a more complete example of defining zones and zone ranges for
initial chunk distribution on a compound hashed shard key, see
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-pre-define-zone-range-hashed-example" target="_self">
      <span>
       Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection
       <!-- -->
       .
      </span>
     </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>
   </section>
  </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">
    After associating a range to a zone, the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-balancing-internals">
     balancer
    </a>
    must first run in order to migrate any chunks
whose ranges are covered by the zone to shards inside of that zone. Until
balancing completes, some chunks may reside on the wrong shard given the
configured zones for the sharded cluster. See
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding-balancer">
     Balancer
    </a>
    for more information.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    See the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-balancing">
     sharded cluster balancer
    </a>
    manual page for
more information on how migrations work in a sharded cluster.
   </p>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Bounds
    <a class="headerlink leafygreen-ui-1kepx47" href="#bounds" 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="bounds">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    Zone ranges are always inclusive of the lower boundary and exclusive
of the upper boundary.
   </p>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Dropped Collections
    <a class="headerlink leafygreen-ui-1kepx47" href="#dropped-collections" 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="dropped-collections">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    Dropping a collection deletes its associated zone/tag ranges.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    In earlier versions, MongoDB does not remove the tag associations for a
dropped collection, and if you later create a new collection with the
same name, the old tag associations will apply to the new collection.
   </p>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Security
    <a class="headerlink leafygreen-ui-1kepx47" href="#security" 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="security">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    For sharded clusters running with
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/#std-label-authentication">
     authentication
    </a>
    , you
must authenticate as either:
   </p>
   <ul class="leafygreen-ui-rioki0">
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      a user whose privileges include the specified actions on various
collections in the
      <code class="leafygreen-ui-1l06pbn">
       config
      </code>
      database:
     </p>
     <ul class="leafygreen-ui-rioki0">
      <li class="leafygreen-ui-d7p7b6">
       <p class="leafygreen-ui-1kp3ins">
        <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find">
         <code class="leafygreen-ui-1l06pbn">
          find
         </code>
        </a>
        on the
        <code class="leafygreen-ui-1l06pbn">
         config.shards
        </code>
        collection
       </p>
      </li>
      <li class="leafygreen-ui-d7p7b6">
       <p class="leafygreen-ui-1kp3ins">
        <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find">
         <code class="leafygreen-ui-1l06pbn">
          find
         </code>
        </a>
        and
        <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-update">
         <code class="leafygreen-ui-1l06pbn">
          update
         </code>
        </a>
        on the
        <code class="leafygreen-ui-1l06pbn">
         config.tags
        </code>
        collection;
       </p>
      </li>
     </ul>
     <p class="leafygreen-ui-1kp3ins">
      or, alternatively,
     </p>
    </li>
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      a user whose privileges include
      <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-enableSharding">
       <code class="leafygreen-ui-1l06pbn">
        enableSharding
       </code>
      </a>
      on the
      <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/resource-document/#std-label-resource-specific-collection">
       cluster
      </a>
      resource.
     </p>
    </li>
   </ul>
   <p class="leafygreen-ui-1kp3ins">
    The
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterAdmin">
     <code class="leafygreen-ui-1l06pbn">
      clusterAdmin
     </code>
    </a>
    or
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterManager">
     <code class="leafygreen-ui-1l06pbn">
      clusterManager
     </code>
    </a>
    built-in roles have
the appropriate permissions for issuing
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.updateZoneKeyRange" target="_self">
     <span>
      <code class="leafygreen-ui-1l06pbn">
       sh.updateZoneKeyRange()
      </code>
     </span>
    </a>
    . See
the documentation page for
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/#std-label-authorization">
     Role-Based Access Control
    </a>
    for more information.
   </p>
  </section>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Examples
   <a class="headerlink leafygreen-ui-1kepx47" href="#examples" 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="examples">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   Given a sharded collection
   <code class="leafygreen-ui-1l06pbn">
    exampledb.collection
   </code>
   with a shard key of
   <code class="leafygreen-ui-1l06pbn">
    { a
: 1 }
   </code>
   , the following operation creates a range with a lower bound of
   <code class="leafygreen-ui-1l06pbn">
    1
   </code>
   and an upper bound of
   <code class="leafygreen-ui-1l06pbn">
    10
   </code>
   on the
   <code class="leafygreen-ui-1l06pbn">
    alpha
   </code>
   zone:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.updateZoneKeyRange(\n   \"exampledb.collection\",\n   { a : 1 },\n   { a : 10 },\n   \"alpha\"\n)","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">sh.<span class="lg-highlight-title lg-highlight-function">updateZoneKeyRange</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"exampledb.collection"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">10</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"alpha"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</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>
  <p class="leafygreen-ui-1kp3ins">
   The following operation removes the previously created range by passing
   <code class="leafygreen-ui-1l06pbn">
    null
   </code>
   to the
   <code class="leafygreen-ui-1l06pbn">
    zone
   </code>
   field.
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.updateZoneKeyRange(\n   \"exampledb.collection\",\n   { a : 1 },\n   { a : 10 },\n   null\n)","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">sh.<span class="lg-highlight-title lg-highlight-function">updateZoneKeyRange</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"exampledb.collection"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">10</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-literal">null</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</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>
  <p class="leafygreen-ui-1kp3ins">
   The
   <code class="leafygreen-ui-1l06pbn">
    min
   </code>
   and
   <code class="leafygreen-ui-1l06pbn">
    max
   </code>
   must match exactly the bounds of the target range.
The following operation attempts to remove the previously created range, but
specifies
   <code class="leafygreen-ui-1l06pbn">
    { a : 0 }
   </code>
   as the
   <code class="leafygreen-ui-1l06pbn">
    min
   </code>
   bound:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.updateZoneKeyRange(\n   \"exampledb.collection\",\n   { a : 0 },\n   { a : 10 },\n   null\n)","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">sh.<span class="lg-highlight-title lg-highlight-function">updateZoneKeyRange</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"exampledb.collection"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">0</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">10</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-literal">null</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</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>
  <p class="leafygreen-ui-1kp3ins">
   While the range of
   <code class="leafygreen-ui-1l06pbn">
    { a : 0 }
   </code>
   and
   <code class="leafygreen-ui-1l06pbn">
    { a : 10 }
   </code>
   encompasses the existing
range, it is not an exact match and therefore
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/updateZoneKeyRange/#mongodb-dbcommand-dbcmd.updateZoneKeyRange">
    <code class="leafygreen-ui-1l06pbn">
     updateZoneKeyRange
    </code>
   </a>
   does not remove anything.
  </p>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Compound Shard Key
    <a class="headerlink leafygreen-ui-1kepx47" href="#compound-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="compound-shard-key">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    Given a sharded collection
    <code class="leafygreen-ui-1l06pbn">
     exampledb.collection
    </code>
    with a shard key of
    <code class="leafygreen-ui-1l06pbn">
     { a
: 1, b : 1 }
    </code>
    , the following operation creates a range covering the lower
bound of
    <code class="leafygreen-ui-1l06pbn">
     { a: 1, b : 1 }
    </code>
    and an upper bound of
    <code class="leafygreen-ui-1l06pbn">
     { a : 10, b : 10}
    </code>
    and associates it
with the
    <code class="leafygreen-ui-1l06pbn">
     alpha
    </code>
    zone:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.updateZoneKeyRange(\n   \"exampledb.collection\",\n   { a : 1, b : 1 },\n   { a : 10, b : 10 },\n   \"alpha\"\n)","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">sh.<span class="lg-highlight-title lg-highlight-function">updateZoneKeyRange</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"exampledb.collection"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">1</span>, <!-- -->b <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">10</span>, <!-- -->b <!-- -->: <span class="lg-highlight-number">10</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"alpha"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</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>
   <span class="leafygreen-ui-1qnjd6d" id="std-label-pre-define-zone-range-example">
   </span>
   <span class="leafygreen-ui-1qnjd6d" id="std-label-pre-define-zone-range-hashed-example">
   </span>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection
    <a class="headerlink leafygreen-ui-1kepx47" href="#pre-define-zones-and-zone-ranges-for-an-empty-or-non-existing-collection" 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="pre-define-zones-and-zone-ranges-for-an-empty-or-non-existing-collection">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    If you create zones and zone ranges on empty or non-existing collections,
MongoDB may optimize the initial chunk creation and distribution process when
sharding the collection. This optimized process supports faster setup of zoned
sharding with less balancer overhead than creating zones after sharding. The
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-balancing">
     balancer
    </a>
    performs all chunk management after the
optimized initial chunk creation and distribution. For more information, see
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-updateZoneKeyRange-method-init-chunk-distribution-compound-hashed" target="_self">
     <span>
      Initial Chunk Distribution with Compound Hashed Shard Keys
     </span>
    </a>
    for more information.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    The sections below contain examples for three different shard key types.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    Consider the following examples, which explore pre-defining zones or
zone ranges for three different shard key types:
   </p>
   <ul class="leafygreen-ui-rioki0">
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-updatezonekeyrange-single-or-compound-example" target="_self">
       <span>
        Single or Compound Shard Keys
       </span>
      </a>
     </p>
    </li>
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-updatezonekeyrange-compound-prefix-hashed-example" target="_self">
       <span>
        Compound Hashed Shard Key with Hashed Prefix
       </span>
      </a>
     </p>
    </li>
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-updatezonekeyrange-compound-non-prefix-hashed-example" target="_self">
       <span>
        Compound Hashed Shard Key with Non-Prefix Hashed Field
       </span>
      </a>
     </p>
    </li>
   </ul>
   <span class="leafygreen-ui-1qnjd6d" id="std-label-updatezonekeyrange-single-or-compound-example">
   </span>
   <section>
    <h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
     Single or Compound Shard Keys
     <a class="headerlink leafygreen-ui-1kepx47" href="#single-or-compound-shard-keys" 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="single-or-compound-shard-keys">
      </div>
     </a>
    </h4>
    <div class="leafygreen-ui-15mdk4" role="note">
     <h2 class="leafygreen-ui-6n7b7d">
      Note
     </h2>
     <div class="leafygreen-ui-9mycqc">
      <p class="leafygreen-ui-1kp3ins">
       This example only applies to single-field or compound shard keys
       <em>
        without
       </em>
       a hashed field.
      </p>
      <p class="leafygreen-ui-1kp3ins">
       For example,
       <code class="leafygreen-ui-1l06pbn">
        { "zip" : 1 }
       </code>
       or
       <code class="leafygreen-ui-1l06pbn">
        { "zip" : 1, "account" : 1}
       </code>
      </p>
     </div>
    </div>
    <script class="structured_data" type="application/ld+json">
     {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Create the ZonesUse sh.addShardToZone() to create the zones:"},{"@type":"HowToStep","text":"Create the Zone RangesUse sh.updateZoneKeyRange() to create the ranges\nfor the empty contacts collection in the exampledb\ndatabase:"},{"@type":"HowToStep","text":"Shard the CollectionIf the collection does not exist, the sharding operation creates\nthe collection.If the collection is empty and no index exists to support the\nshard key, the sharding operation creates the index.Use sh.shardCollection() to shard the collection contacts:"},{"@type":"HowToStep","text":"Review the Created Chunks and DistributionTo see the created chunks and distribution, run the\nsh.status() operation:The method returns:For the collection, sharding operation created 5 chunks (two chunks\nthat correspond to the zone ranges and the other three to cover all\nother values) across shardA and shardB."}],"name":"Single or Compound Shard Keys","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
    </script>
    <div class="css-4nyere eccljxs0">
     <div class="css-1nuklj8 e1ckbxcu1">
      <div class="css-18fui5z e1ckbxcu0">
       <div class="css-19lsqsq e1ckbxcu2">
        1
       </div>
      </div>
      <div class="css-1ed38mk">
       <section>
        <h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
         Create the Zones
         <a class="headerlink leafygreen-ui-1kepx47" href="#create-the-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="create-the-zones">
          </div>
         </a>
        </h5>
        <p class="leafygreen-ui-1kp3ins">
         Use
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addShardToZone/#mongodb-method-sh.addShardToZone">
          <code class="leafygreen-ui-1l06pbn">
           sh.addShardToZone()
          </code>
         </a>
         to create the zones:
        </p>
        <script class="structured_data" type="application/ld+json">
         {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.addShardToZone(\"shardA\", \"DC1\")\nsh.addShardToZone(\"shardB\", \"DC2\")","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">sh.<span class="lg-highlight-title lg-highlight-function">addShardToZone</span>(<span class="lg-highlight-string">"shardA"</span>, <span class="lg-highlight-string">"DC1"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">sh.<span class="lg-highlight-title lg-highlight-function">addShardToZone</span>(<span class="lg-highlight-string">"shardB"</span>, <span class="lg-highlight-string">"DC2"</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>
       </section>
      </div>
     </div>
     <div class="css-1nuklj8 e1ckbxcu1">
      <div class="css-18fui5z e1ckbxcu0">
       <div class="css-19lsqsq e1ckbxcu2">
        2
       </div>
      </div>
      <div class="css-1ed38mk">
       <section>
        <h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
         Create the Zone Ranges
         <a class="headerlink leafygreen-ui-1kepx47" href="#create-the-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="create-the-zone-ranges">
          </div>
         </a>
        </h5>
        <p class="leafygreen-ui-1kp3ins">
         Use
         <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.updateZoneKeyRange" target="_self">
          <span>
           <code class="leafygreen-ui-1l06pbn">
            sh.updateZoneKeyRange()
           </code>
          </span>
         </a>
         to create the ranges
for the empty
         <code class="leafygreen-ui-1l06pbn">
          contacts
         </code>
         collection in the
         <code class="leafygreen-ui-1l06pbn">
          exampledb
         </code>
         database:
        </p>
        <script class="structured_data" type="application/ld+json">
         {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.updateZoneKeyRange(\n    \"exampledb.contacts\",\n    { zip: 10001 },\n    { zip: 10090 },\n    \"DC1\"\n);\n\nsh.updateZoneKeyRange(\n    \"exampledb.contacts\",\n    { zip: 90001 },\n    { zip: 96054 },\n    \"DC2\"\n);","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">sh.<span class="lg-highlight-title lg-highlight-function">updateZoneKeyRange</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"exampledb.contacts"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <!-- -->{ <span class="lg-highlight-attr">zip</span>: <span class="lg-highlight-number">10001</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <!-- -->{ <span class="lg-highlight-attr">zip</span>: <span class="lg-highlight-number">10090</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"DC1"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">)<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">sh.<span class="lg-highlight-title lg-highlight-function">updateZoneKeyRange</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"exampledb.contacts"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <!-- -->{ <span class="lg-highlight-attr">zip</span>: <span class="lg-highlight-number">90001</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <!-- -->{ <span class="lg-highlight-attr">zip</span>: <span class="lg-highlight-number">96054</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"DC2"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">)<!-- -->;</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>
       </section>
      </div>
     </div>
     <div class="css-1nuklj8 e1ckbxcu1">
      <div class="css-18fui5z e1ckbxcu0">
       <div class="css-19lsqsq e1ckbxcu2">
        3
       </div>
      </div>
      <div class="css-1ed38mk">
       <section>
        <h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
         Shard the Collection
         <a class="headerlink leafygreen-ui-1kepx47" href="#shard-the-collection" 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-the-collection">
          </div>
         </a>
        </h5>
        <div class="leafygreen-ui-15mdk4" role="note">
         <h2 class="leafygreen-ui-6n7b7d">
          Note
         </h2>
         <div class="leafygreen-ui-9mycqc">
          <p class="leafygreen-ui-1kp3ins">
           If the collection does not exist, the sharding operation creates
the collection.
          </p>
          <p class="leafygreen-ui-1kp3ins">
           If the collection is empty and no index exists to support the
shard key, the sharding operation creates the index.
          </p>
         </div>
        </div>
        <p class="leafygreen-ui-1kp3ins">
         Use
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection">
          <code class="leafygreen-ui-1l06pbn">
           sh.shardCollection()
          </code>
         </a>
         to shard the collection
         <code class="leafygreen-ui-1l06pbn">
          contacts
         </code>
         :
        </p>
        <script class="structured_data" type="application/ld+json">
         {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.shardCollection(\"exampledb.contacts\",  { zip: 1 } );","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">sh.<span class="lg-highlight-title lg-highlight-function">shardCollection</span>(<span class="lg-highlight-string">"exampledb.contacts"</span>,  <!-- -->{ <span class="lg-highlight-attr">zip</span>: <span class="lg-highlight-number">1</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>
       </section>
      </div>
     </div>
     <div class="css-1nuklj8 e1ckbxcu1">
      <div class="css-18fui5z e1ckbxcu0">
       <div class="css-19lsqsq e1ckbxcu2">
        4
       </div>
      </div>
      <div class="css-1ed38mk">
       <section>
        <h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
         Review the Created Chunks and Distribution
         <a class="headerlink leafygreen-ui-1kepx47" href="#review-the-created-chunks-and-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="review-the-created-chunks-and-distribution">
          </div>
         </a>
        </h5>
        <p class="leafygreen-ui-1kp3ins">
         To see the created chunks and distribution, run the
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.status/#mongodb-method-sh.status">
          <code class="leafygreen-ui-1l06pbn">
           sh.status()
          </code>
         </a>
         operation:
        </p>
        <script class="structured_data" type="application/ld+json">
         {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.status()","programmingLanguage":"JavaScript"}
        </script>
        <div class="css-16lmvu9">
         <div class="leafygreen-ui-196mwvg">
          <div class="leafygreen-ui-yzcs8i">
           <pre class="leafygreen-ui-1q4bxgx" 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">sh.<span class="lg-highlight-title lg-highlight-function">status</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>
        <p class="leafygreen-ui-1kp3ins">
         The method returns:
        </p>
        <script class="structured_data" type="application/ld+json">
         {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"--- Sharding Status ---\n  sharding version: {\n    \"_id\" : 1,\n    \"minCompatibleVersion\" : 5,\n    \"currentVersion\" : 6,\n    \"clusterId\" : ObjectId(\"5b80c06d35a961fd0ae1986d\")\n  }\n  shards:\n        {  \"_id\" : \"shardA\",  \"host\" : \"shardA/mongodb0.example.net:27018,mongodb1.example.net:27018,mongodb2.example.net:27018\",  \"state\" : 1,  \"tags\" : [ \"DC1\" ] }\n        {  \"_id\" : \"shardB\",  \"host\" : \"shardB/mongodb3.example.net:27018,mongodb4.example.net:27018,mongodb5.example.net:27018\",  \"state\" : 1,  \"tags\" : [ \"DC2\" ] }\n  active mongoses:\n        \"4.2.0\" : 2\n  autosplit:\n        Currently enabled: yes\n  balancer:\n        Currently enabled:  yes\n        Currently running:  no\n        Failed balancer rounds in last 5 attempts:  0\n        Migration Results for the last 24 hours:\n                No recent migrations\n  databases:\n        { \"_id\" : \"config\", \"primary\" : \"config\" }\n        { \"_id\" : \"exampledb\", \"primary\" : \"shardA\", \"version\" : { \"uuid\" : UUID(\"6c351bcf-acd2-4fd9-82d8-9f6bd7321558\"), \"lastMod\" : 1 } }\n                exampledb.contacts\n                        shard key: { \"zip\" : 1 }\n                        unique: false\n                        balancing: true\n                        chunks:\n                                shardA   3\n                                shardB   2\n                        { \"zip\" : { \"$minKey\" : 1 } } --&gt;&gt; { \"zip\" : 10001 } on : shardA Timestamp(1, 0)\n                        { \"zip\" : 10001 } --&gt;&gt; { \"zip\" : 10090 } on : shardA Timestamp(1, 1)\n                        { \"zip\" : 10090 } --&gt;&gt; { \"zip\" : 90001 } on : shardB Timestamp(1, 2)\n                        { \"zip\" : 90001 } --&gt;&gt; { \"zip\" : 96054 } on : shardB Timestamp(1, 3)\n                        { \"zip\" : 96054 } --&gt;&gt; { \"zip\" : { \"$maxKey\" : 1 } } on : shardA Timestamp(1, 4)\n                          tag: DC1  { \"zip\" : 10001 } --&gt;&gt; { \"zip\" : 10090 }\n                          tag: DC2  { \"zip\" : 90001 } --&gt;&gt; { \"zip\" : 96054 }","programmingLanguage":"JavaScript"}
        </script>
        <div class="css-16lmvu9">
         <div class="leafygreen-ui-196mwvg">
          <div class="leafygreen-ui-1b1bvay">
           <pre class="leafygreen-ui-11itue3" 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-title lg-highlight-class">Sharding</span> <span class="lg-highlight-title lg-highlight-class">Status</span> <!-- -->-<!-- -->-<!-- -->-</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->sharding <span class="lg-highlight-attr">version</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"minCompatibleVersion"</span> <!-- -->: <span class="lg-highlight-number">5</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"currentVersion"</span> <!-- -->: <span class="lg-highlight-number">6</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"clusterId"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"5b80c06d35a961fd0ae1986d"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-attr">shards</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">        <!-- -->{  <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"shardA"</span>,  <span class="lg-highlight-string">"host"</span> <!-- -->: <span class="lg-highlight-string">"shardA/mongodb0.example.net:27018,mongodb1.example.net:27018,mongodb2.example.net:27018"</span>,  <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-number">1</span>,  <span class="lg-highlight-string">"tags"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"DC1"</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">        <!-- -->{  <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"shardB"</span>,  <span class="lg-highlight-string">"host"</span> <!-- -->: <span class="lg-highlight-string">"shardB/mongodb3.example.net:27018,mongodb4.example.net:27018,mongodb5.example.net:27018"</span>,  <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-number">1</span>,  <span class="lg-highlight-string">"tags"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"DC2"</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  active <span class="lg-highlight-attr">mongoses</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">        <span class="lg-highlight-string">"4.2.0"</span> <!-- -->: <span class="lg-highlight-number">2</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-attr">autosplit</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">        <span class="lg-highlight-title lg-highlight-class">Currently</span> <span class="lg-highlight-attr">enabled</span>: <!-- -->yes</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-attr">balancer</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">        <span class="lg-highlight-title lg-highlight-class">Currently</span> <span class="lg-highlight-attr">enabled</span>:  <!-- -->yes</td></tr><tr class=""><td class="leafygreen-ui-7razhx">        <span class="lg-highlight-title lg-highlight-class">Currently</span> <span class="lg-highlight-attr">running</span>:  <!-- -->no</td></tr><tr class=""><td class="leafygreen-ui-7razhx">        <span class="lg-highlight-title lg-highlight-class">Failed</span> balancer rounds <span class="lg-highlight-keyword">in</span> last <span class="lg-highlight-number">5</span> <span class="lg-highlight-attr">attempts</span>:  <span class="lg-highlight-number">0</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">        <span class="lg-highlight-title lg-highlight-class">Migration</span> <span class="lg-highlight-title lg-highlight-class">Results</span> <span class="lg-highlight-keyword">for</span> the last <span class="lg-highlight-number">24</span> <span class="lg-highlight-attr">hours</span>:</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">                <span class="lg-highlight-title lg-highlight-class">No</span> recent migrations</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-attr">databases</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">        <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"config"</span>, <span class="lg-highlight-string">"primary"</span> <!-- -->: <span class="lg-highlight-string">"config"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">        <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"exampledb"</span>, <span class="lg-highlight-string">"primary"</span> <!-- -->: <span class="lg-highlight-string">"shardA"</span>, <span class="lg-highlight-string">"version"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"uuid"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-function">UUID</span>(<span class="lg-highlight-string">"6c351bcf-acd2-4fd9-82d8-9f6bd7321558"</span>)<!-- -->, <span class="lg-highlight-string">"lastMod"</span> <!-- -->: <span class="lg-highlight-number">1</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                exampledb.<span class="lg-highlight-property">contacts</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">                        shard <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">1</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                        <span class="lg-highlight-attr">unique</span>: <span class="lg-highlight-literal">false</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">                        <span class="lg-highlight-attr">balancing</span>: <span class="lg-highlight-literal">true</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">                        <span class="lg-highlight-attr">chunks</span>:</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">                                <!-- -->shardA   <span class="lg-highlight-number">3</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">                                shardB   <span class="lg-highlight-number">2</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">                        <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->&gt;&gt; <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">10001</span> } on <!-- -->: <!-- -->shardA <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">0</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">                        <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">10001</span> } <!-- -->-<!-- -->-<!-- -->&gt;&gt; <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">10090</span> } on <!-- -->: <!-- -->shardA <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">1</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                        <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">10090</span> } <!-- -->-<!-- -->-<!-- -->&gt;&gt; <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">90001</span> } on <!-- -->: <!-- -->shardB <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">2</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">                        <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">90001</span> } <!-- -->-<!-- -->-<!-- -->&gt;&gt; <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">96054</span> } on <!-- -->: <!-- -->shardB <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">3</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                        <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">96054</span> } <!-- -->-<!-- -->-<!-- -->&gt;&gt; <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$maxKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } on <!-- -->: <!-- -->shardA <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">4</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">                          <span class="lg-highlight-attr">tag</span>: <span class="lg-highlight-title lg-highlight-class">DC1</span>  <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">10001</span> } <!-- -->-<!-- -->-<!-- -->&gt;&gt; <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">10090</span> }</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">                          <span class="lg-highlight-attr">tag</span>: <span class="lg-highlight-title lg-highlight-class">DC2</span>  <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">90001</span> } <!-- -->-<!-- -->-<!-- -->&gt;&gt; <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">96054</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>
        <p class="leafygreen-ui-1kp3ins">
         For the collection, sharding operation created 5 chunks (two chunks
that correspond to the zone ranges and the other three to cover all
other values) across shardA and shardB.
        </p>
       </section>
      </div>
     </div>
    </div>
    <span class="leafygreen-ui-1qnjd6d" id="std-label-updatezonekeyrange-compound-prefix-hashed-example">
    </span>
   </section>
   <section>
    <h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
     Compound Hashed Shard Key with Hashed Prefix
     <a class="headerlink leafygreen-ui-1kepx47" href="#compound-hashed-shard-key-with-hashed-prefix" 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="compound-hashed-shard-key-with-hashed-prefix">
      </div>
     </a>
    </h4>
    <div class="leafygreen-ui-15mdk4" role="note">
     <h2 class="leafygreen-ui-6n7b7d">
      Note
     </h2>
     <div class="leafygreen-ui-9mycqc">
      <p class="leafygreen-ui-1kp3ins">
       This example only applies to compound hashed shard keys where the
hashed field is the prefix of the shard key (i.e. the first field in
the shard key is hashed).
      </p>
      <p class="leafygreen-ui-1kp3ins">
       For example,
       <code class="leafygreen-ui-1l06pbn">
        { "_id" : "hashed", "facility" : 1 }
       </code>
      </p>
     </div>
    </div>
    <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 on a compound hashed shard key, MongoDB can perform
optimized initial chunk creation and distribution on the empty or
non-existing collection
     <em>
      only if
     </em>
     the defined zone ranges meet
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-updateZoneKeyRange-method-init-chunk-distribution" target="_self">
      <span>
       additional requirements
       <!-- -->
       .
      </span>
     </a>
    </p>
    <p class="leafygreen-ui-1kp3ins">
     Consider an empty collection
     <code class="leafygreen-ui-1l06pbn">
      examples.metrics
     </code>
     which will store
analytics from one of two manufacturing facilities. The
planned shard key is
     <code class="leafygreen-ui-1l06pbn">
      { "_id" : "hashed", "facility" : 1}
     </code>
     ,
where the hashed field is the shard key
     <em>
      prefix
     </em>
     .
    </p>
    <script class="structured_data" type="application/ld+json">
     {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Create the ZonesThe planned shard key is { \"_id\" : \"hashed\", \"facility\" : 1 }.\nSince the hashed field is the prefix (i.e. the first field in the\nshard key), create a single zone using\nsh.addShardToZone():"},{"@type":"HowToStep","text":"Create the Zone RangesInitial chunk distribution on a compound hashed shard key with a\nhashed prefix requires a single zone range with MinKey for all\nlower-bound fields and MaxKey for all upper-bound fields.Use sh.updateZoneKeyRange() to create a single range:"},{"@type":"HowToStep","text":"Shard the CollectionIf the collection does not exist, the sharding operation creates\nthe collection.If the collection is empty and no index exists to support the\nshard key, the sharding operation creates the index.Use sh.shardCollection() with\npresplitHashedZones: true to shard the\ncollection and perform initial chunk creation and distribution:"},{"@type":"HowToStep","text":"Review the Created Chunks and DistributionTo see the created chunks and distribution, run the\nsh.status() operation:The output resembles the following\n(content omitted for  readability):The sharding operation produced 4 chunks in total. Two chunks\ncorrespond to the absolute lower and upper bounds. One zone was\ncreated on shardA and shardB corresponding to\nFacilityAlpha. The zone was subdivided into 2 chunks using the\nhashed field."}],"name":"Compound Hashed Shard Key with Hashed Prefix","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
    </script>
    <div class="css-4nyere eccljxs0">
     <div class="css-1nuklj8 e1ckbxcu1">
      <div class="css-18fui5z e1ckbxcu0">
       <div class="css-19lsqsq e1ckbxcu2">
        1
       </div>
      </div>
      <div class="css-1ed38mk">
       <section>
        <h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
         Create the Zones
         <a class="headerlink leafygreen-ui-1kepx47" href="#create-the-zones-1" 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="create-the-zones-1">
          </div>
         </a>
        </h5>
        <p class="leafygreen-ui-1kp3ins">
         The planned shard key is
         <code class="leafygreen-ui-1l06pbn">
          { "_id" : "hashed", "facility" : 1 }
         </code>
         .
Since the hashed field is the prefix (i.e. the first field in the
shard key), create a
         <em>
          single
         </em>
         zone using
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addShardToZone/#mongodb-method-sh.addShardToZone">
          <code class="leafygreen-ui-1l06pbn">
           sh.addShardToZone()
          </code>
          :
         </a>
        </p>
        <script class="structured_data" type="application/ld+json">
         {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.addShardToZone(\"shardA\", \"FacilityAlpha\")\nsh.addShardToZone(\"shardB\", \"FacilityAlpha\")","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">sh.<span class="lg-highlight-title lg-highlight-function">addShardToZone</span>(<span class="lg-highlight-string">"shardA"</span>, <span class="lg-highlight-string">"FacilityAlpha"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">sh.<span class="lg-highlight-title lg-highlight-function">addShardToZone</span>(<span class="lg-highlight-string">"shardB"</span>, <span class="lg-highlight-string">"FacilityAlpha"</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>
       </section>
      </div>
     </div>
     <div class="css-1nuklj8 e1ckbxcu1">
      <div class="css-18fui5z e1ckbxcu0">
       <div class="css-19lsqsq e1ckbxcu2">
        2
       </div>
      </div>
      <div class="css-1ed38mk">
       <section>
        <h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
         Create the Zone Ranges
         <a class="headerlink leafygreen-ui-1kepx47" href="#create-the-zone-ranges-1" 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="create-the-zone-ranges-1">
          </div>
         </a>
        </h5>
        <p class="leafygreen-ui-1kp3ins">
         Initial chunk distribution on a compound hashed shard key with a
hashed prefix requires a single zone range with
         <code class="leafygreen-ui-1l06pbn">
          MinKey
         </code>
         for all
lower-bound fields and
         <code class="leafygreen-ui-1l06pbn">
          MaxKey
         </code>
         for all upper-bound fields.
        </p>
        <p class="leafygreen-ui-1kp3ins">
         Use
         <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.updateZoneKeyRange" target="_self">
          <span>
           <code class="leafygreen-ui-1l06pbn">
            sh.updateZoneKeyRange()
           </code>
          </span>
         </a>
         to create a single range:
        </p>
        <script class="structured_data" type="application/ld+json">
         {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.updateZoneKeyRange(\n   \"examples.metrics\",\n   { \"_id\" : MinKey, \"facility\" : MinKey },\n   { \"_id\" : MaxKey, \"facility\" : MaxKey },\n   \"FacilityAlpha\"\n);","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">sh.<span class="lg-highlight-title lg-highlight-function">updateZoneKeyRange</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"examples.metrics"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">MinKey</span>, <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">MinKey</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">MaxKey</span>, <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">MaxKey</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"FacilityAlpha"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">)<!-- -->;</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>
       </section>
      </div>
     </div>
     <div class="css-1nuklj8 e1ckbxcu1">
      <div class="css-18fui5z e1ckbxcu0">
       <div class="css-19lsqsq e1ckbxcu2">
        3
       </div>
      </div>
      <div class="css-1ed38mk">
       <section>
        <h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
         Shard the Collection
         <a class="headerlink leafygreen-ui-1kepx47" href="#shard-the-collection-1" 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-the-collection-1">
          </div>
         </a>
        </h5>
        <div class="leafygreen-ui-15mdk4" role="note">
         <h2 class="leafygreen-ui-6n7b7d">
          Note
         </h2>
         <div class="leafygreen-ui-9mycqc">
          <p class="leafygreen-ui-1kp3ins">
           If the collection does not exist, the sharding operation creates
the collection.
          </p>
          <p class="leafygreen-ui-1kp3ins">
           If the collection is empty and no index exists to support the
shard key, the sharding operation creates the index.
          </p>
         </div>
        </div>
        <p class="leafygreen-ui-1kp3ins">
         Use
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection">
          <code class="leafygreen-ui-1l06pbn">
           sh.shardCollection()
          </code>
         </a>
         with
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#std-label-method-shard-collection-presplitHashedZones">
          presplitHashedZones: true
         </a>
         to shard the
collection and perform initial chunk creation and distribution:
        </p>
        <script class="structured_data" type="application/ld+json">
         {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.shardCollection(\n  \"examples.metrics\",\n  { \"_id\" : \"hashed\", \"facility\" : 1 },\n  false,\n  { presplitHashedZones: true }\n)","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">sh.<span class="lg-highlight-title lg-highlight-function">shardCollection</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-string">"examples.metrics"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"hashed"</span>, <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->{ <span class="lg-highlight-attr">presplitHashedZones</span>: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</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>
       </section>
      </div>
     </div>
     <div class="css-1nuklj8 e1ckbxcu1">
      <div class="css-18fui5z e1ckbxcu0">
       <div class="css-19lsqsq e1ckbxcu2">
        4
       </div>
      </div>
      <div class="css-1ed38mk">
       <section>
        <h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
         Review the Created Chunks and Distribution
         <a class="headerlink leafygreen-ui-1kepx47" href="#review-the-created-chunks-and-distribution-1" 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="review-the-created-chunks-and-distribution-1">
          </div>
         </a>
        </h5>
        <p class="leafygreen-ui-1kp3ins">
         To see the created chunks and distribution, run the
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.status/#mongodb-method-sh.status">
          <code class="leafygreen-ui-1l06pbn">
           sh.status()
          </code>
         </a>
         operation:
        </p>
        <script class="structured_data" type="application/ld+json">
         {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.status()","programmingLanguage":"JavaScript"}
        </script>
        <div class="css-16lmvu9">
         <div class="leafygreen-ui-196mwvg">
          <div class="leafygreen-ui-yzcs8i">
           <pre class="leafygreen-ui-1q4bxgx" 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">sh.<span class="lg-highlight-title lg-highlight-function">status</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>
        <p class="leafygreen-ui-1kp3ins">
         The output resembles the following
(
         <em>
          content omitted for  readability
         </em>
         ):
        </p>
        <script class="structured_data" type="application/ld+json">
         {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"--- Sharding Status ---\n\ndatabases:\n  { \"_id\" : \"config\", \"primary\" : \"config\" }\n  { \"_id\" : \"examples\", \"primary\" : \"shardA\", \"version\" : { \"uuid\" : UUID(\"245f8abf-a363-48b0-8208-2a5b577bbb4e\"), \"lastMod\" : 1 } }\n    examples.metrics\n      shard key: { \"_id\" : \"hashed\", \"facility\" : 1 }\n      unique: false\n      balancing: true\n      chunks:\n        shardA  2\n        shardB  2\n      { \"_id\" : { \"$minKey\" : 1 }, \"facility\" : { \"$minKey\" : 1 } } --&gt;&gt; { \"_id\" : NumberLong(\"-4611686018427387902\"), \"facility\" : { \"$minKey\" : 1 } } on : shardA Timestamp(1, 0)\n      { \"_id\" : NumberLong(\"-4611686018427387902\"), \"facility\" : { \"$minKey\" : 1 } } --&gt;&gt; { \"_id\" : NumberLong(0), \"facility\" : { \"$minKey\" : 1 } } on : shardA Timestamp(1, 1)\n      { \"_id\" : NumberLong(0), \"facility\" : { \"$minKey\" : 1 } } --&gt;&gt; { \"_id\" : NumberLong(\"4611686018427387902\"), \"facility\" : { \"$minKey\" : 1 } } on : shardB Timestamp(1, 2)\n      { \"_id\" : NumberLong(\"4611686018427387902\"), \"facility\" : { \"$minKey\" : 1 } } --&gt;&gt; { \"_id\" : { \"$maxKey\" : 1 }, \"facility\" : { \"$maxKey\" : 1 } } on : shardB Timestamp(1, 3)\n\n        tag: FacilityAlpha  { \"_id\" : { \"$minKey\" : 1 }, \"facility\" : { \"$minKey\" : 1 } } --&gt;&gt; { \"_id\" : { \"$maxKey\" : 1 }, \"facility\" : { \"$maxKey\" : 1 } }","programmingLanguage":"JavaScript"}
        </script>
        <div class="css-16lmvu9">
         <div class="leafygreen-ui-196mwvg">
          <div class="leafygreen-ui-1b1bvay">
           <pre class="leafygreen-ui-11itue3" 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-title lg-highlight-class">Sharding</span> <span class="lg-highlight-title lg-highlight-class">Status</span> <!-- -->-<!-- -->-<!-- -->-</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">databases</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"config"</span>, <span class="lg-highlight-string">"primary"</span> <!-- -->: <span class="lg-highlight-string">"config"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"examples"</span>, <span class="lg-highlight-string">"primary"</span> <!-- -->: <span class="lg-highlight-string">"shardA"</span>, <span class="lg-highlight-string">"version"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"uuid"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-function">UUID</span>(<span class="lg-highlight-string">"245f8abf-a363-48b0-8208-2a5b577bbb4e"</span>)<!-- -->, <span class="lg-highlight-string">"lastMod"</span> <!-- -->: <span class="lg-highlight-number">1</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    examples.<span class="lg-highlight-property">metrics</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">      shard <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"hashed"</span>, <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-number">1</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">unique</span>: <span class="lg-highlight-literal">false</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">balancing</span>: <span class="lg-highlight-literal">true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">chunks</span>:</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">        <!-- -->shardA  <span class="lg-highlight-number">2</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">        shardB  <span class="lg-highlight-number">2</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">      <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->&gt;&gt; <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"-4611686018427387902"</span>)<!-- -->, <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } on <!-- -->: <!-- -->shardA <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">0</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">      <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"-4611686018427387902"</span>)<!-- -->, <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->&gt;&gt; <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">0</span>)<!-- -->, <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } on <!-- -->: <!-- -->shardA <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">1</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">      <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">0</span>)<!-- -->, <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->&gt;&gt; <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"4611686018427387902"</span>)<!-- -->, <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } on <!-- -->: <!-- -->shardB <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">2</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">      <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"4611686018427387902"</span>)<!-- -->, <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->&gt;&gt; <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$maxKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$maxKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } on <!-- -->: <!-- -->shardB <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">3</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">        <span class="lg-highlight-attr">tag</span>: <span class="lg-highlight-title lg-highlight-class">FacilityAlpha</span>  <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->&gt;&gt; <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$maxKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$maxKey"</span> <!-- -->: <span class="lg-highlight-number">1</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>
        <p class="leafygreen-ui-1kp3ins">
         The sharding operation produced 4 chunks in total. Two chunks
correspond to the absolute lower and upper bounds. One zone was
created on
         <code class="leafygreen-ui-1l06pbn">
          shardA
         </code>
         and
         <code class="leafygreen-ui-1l06pbn">
          shardB
         </code>
         corresponding to
         <code class="leafygreen-ui-1l06pbn">
          FacilityAlpha
         </code>
         . The zone was subdivided into 2 chunks using the
hashed field.
        </p>
       </section>
      </div>
     </div>
    </div>
    <span class="leafygreen-ui-1qnjd6d" id="std-label-updatezonekeyrange-compound-non-prefix-hashed-example">
    </span>
   </section>
   <section>
    <h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
     Compound Hashed Shard Key with Non-Prefix Hashed Field
     <a class="headerlink leafygreen-ui-1kepx47" href="#compound-hashed-shard-key-with-non-prefix-hashed-field" 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="compound-hashed-shard-key-with-non-prefix-hashed-field">
      </div>
     </a>
    </h4>
    <div class="leafygreen-ui-15mdk4" role="note">
     <h2 class="leafygreen-ui-6n7b7d">
      Note
     </h2>
     <div class="leafygreen-ui-9mycqc">
      <p class="leafygreen-ui-1kp3ins">
       This example only applies to compound hashed shard keys where the
hashed field is
       <em>
        not
       </em>
       the prefix of the shard key (i.e. the first
field in the shard key is not hashed).
      </p>
      <p class="leafygreen-ui-1kp3ins">
       For example,
       <code class="leafygreen-ui-1l06pbn">
        { "facility" : 1, "_id" : "hashed" }
       </code>
      </p>
     </div>
    </div>
    <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 on a compound hashed shard key, MongoDB can perform
optimized initial chunk creation and distribution on the empty or
non-existing collection
     <em>
      only if
     </em>
     the defined zone ranges meet
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-updateZoneKeyRange-method-init-chunk-distribution" target="_self">
      <span>
       additional requirements
       <!-- -->
       .
      </span>
     </a>
    </p>
    <p class="leafygreen-ui-1kp3ins">
     Consider an empty collection
     <code class="leafygreen-ui-1l06pbn">
      examples.metrics
     </code>
     which will store
analytics from one of two manufacturing facilities. The planned
shard key is
     <code class="leafygreen-ui-1l06pbn">
      { "facility" : 1, "_id" : "hashed" }
     </code>
     , where
the hashed field is
     <em>
      not
     </em>
     the shard key prefix.
    </p>
    <ul class="leafygreen-ui-rioki0">
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       The
       <code class="leafygreen-ui-1l06pbn">
        facility
       </code>
       field stores the name of the facility:
       <code class="leafygreen-ui-1l06pbn">
        "FacilityAlpha"
       </code>
       or
       <code class="leafygreen-ui-1l06pbn">
        "FacilityBaker"
       </code>
       .  The
collection requires zone ranges on
       <code class="leafygreen-ui-1l06pbn">
        facility
       </code>
       to help isolate
data for each facility to specific shards.
      </p>
     </li>
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       The
       <code class="leafygreen-ui-1l06pbn">
        _id
       </code>
       field compensates for the low-cardinality of the
       <code class="leafygreen-ui-1l06pbn">
        facility
       </code>
       field. Hashing compensates for the
monotonically-increasing nature of the
       <code class="leafygreen-ui-1l06pbn">
        _id
       </code>
       field.
      </p>
     </li>
    </ul>
    <script class="structured_data" type="application/ld+json">
     {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Create the ZonesUse the sh.addShardToZone() command to create the\nzones."},{"@type":"HowToStep","text":"Create the Zone RangesThe planned shard key is {\"facility\" : 1, \"_id\" : \"hashed\"}. The\nfacility field has two possible values: FacilityAlpha and\nFacilityBaker.Initial chunk distribution on a compound hashed shard key where the\nhashed field is not the prefix requires one zone range for each\ncombination of distinct prefix field values (i.e. all fields\npreceding the hashed field). Since facility has two distinct\nprefix values, the collection requires exactly two zone ranges\nthat cover those values.The lower bound range specifies MinKey for all non-prefix\nfields.The upper-bound range has at least one prefix field that\ndiffers from its lower-bound counterpart.Use sh.updateZoneKeyRange() to create the range for\n\"facility\": \"FacilityAlpha\":Since zone range upper bounds are exclusive, this range only\ncovers documents with the distinct shard key prefix value\n\"facilty\" : \"FacilityAlpha\" and all possible values of _id.Use sh.updateZoneKeyRange() to create the range for\n\"facility\": \"FacilityBaker\":While the upper bound of this range can technically\ncapture other values of facility, the initial chunk\ndistribution logic relies on the assumption that no other distinct\nvalues for facility exist. Since the collection only contains\ndocuments where facility is FacilityAlpha or\nFacilityBaker, this range only covers\ndocuments with the distinct shard key prefix value\n\"facility\" : \"FacilityBaker\" and all possible values of\n_id."},{"@type":"HowToStep","text":"Shard the CollectionIf the collection does not exist, the sharding operation creates\nthe collection.If the collection is empty and no index exists to support the\nshard key, the sharding operation creates the index.Use sh.shardCollection() with\npresplitHashedZones: true to shard the\ncollection and perform initial chunk creation and distribution:"},{"@type":"HowToStep","text":"Review the Created Chunks and DistributionTo see the created chunks and distribution, run the\nsh.status() operation:The output resembles the following\n(content omitted for  readability):The sharding operation produced 6 chunks in total. Two chunks\ncorrespond to the absolute lower and upper bounds. Two zones were\ncreated, one on shardA and one on shardB, corresponding to\nFacilityAlpha and FacilityBaker. Each of these zones has been\nfurther subdivided into 2 chunks using the hashed field."}],"name":"Compound Hashed Shard Key with Non-Prefix Hashed Field","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
    </script>
    <div class="css-4nyere eccljxs0">
     <div class="css-1nuklj8 e1ckbxcu1">
      <div class="css-18fui5z e1ckbxcu0">
       <div class="css-19lsqsq e1ckbxcu2">
        1
       </div>
      </div>
      <div class="css-1ed38mk">
       <section>
        <h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
         Create the Zones
         <a class="headerlink leafygreen-ui-1kepx47" href="#create-the-zones-2" 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="create-the-zones-2">
          </div>
         </a>
        </h5>
        <p class="leafygreen-ui-1kp3ins">
         Use the
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addShardToZone/#mongodb-method-sh.addShardToZone">
          <code class="leafygreen-ui-1l06pbn">
           sh.addShardToZone()
          </code>
         </a>
         command to create the
zones.
        </p>
        <script class="structured_data" type="application/ld+json">
         {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.addShardToZone(\"shardA\", \"FacilityAlpha\")\nsh.addShardToZone(\"shardB\", \"FacilityBaker\")","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">sh.<span class="lg-highlight-title lg-highlight-function">addShardToZone</span>(<span class="lg-highlight-string">"shardA"</span>, <span class="lg-highlight-string">"FacilityAlpha"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">sh.<span class="lg-highlight-title lg-highlight-function">addShardToZone</span>(<span class="lg-highlight-string">"shardB"</span>, <span class="lg-highlight-string">"FacilityBaker"</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>
       </section>
      </div>
     </div>
     <div class="css-1nuklj8 e1ckbxcu1">
      <div class="css-18fui5z e1ckbxcu0">
       <div class="css-19lsqsq e1ckbxcu2">
        2
       </div>
      </div>
      <div class="css-1ed38mk">
       <section>
        <h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
         Create the Zone Ranges
         <a class="headerlink leafygreen-ui-1kepx47" href="#create-the-zone-ranges-2" 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="create-the-zone-ranges-2">
          </div>
         </a>
        </h5>
        <p class="leafygreen-ui-1kp3ins">
         The planned shard key is
         <code class="leafygreen-ui-1l06pbn">
          {"facility" : 1, "_id" : "hashed"}
         </code>
         . The
         <code class="leafygreen-ui-1l06pbn">
          facility
         </code>
         field has two possible values:
         <code class="leafygreen-ui-1l06pbn">
          FacilityAlpha
         </code>
         and
         <code class="leafygreen-ui-1l06pbn">
          FacilityBaker
         </code>
         .
        </p>
        <p class="leafygreen-ui-1kp3ins">
         Initial chunk distribution on a compound hashed shard key where the
hashed field is
         <em>
          not
         </em>
         the prefix requires one zone range for each
combination of distinct prefix field values (i.e. all fields
preceding the hashed field). Since
         <code class="leafygreen-ui-1l06pbn">
          facility
         </code>
         has two distinct
prefix values, the collection requires exactly two zone ranges
that cover those values.
        </p>
        <ul class="leafygreen-ui-rioki0">
         <li class="leafygreen-ui-d7p7b6">
          <p class="leafygreen-ui-1kp3ins">
           The lower bound range specifies
           <code class="leafygreen-ui-1l06pbn">
            MinKey
           </code>
           for all non-prefix
fields.
          </p>
         </li>
         <li class="leafygreen-ui-d7p7b6">
          <p class="leafygreen-ui-1kp3ins">
           The upper-bound range has at least one prefix field that
differs from its lower-bound counterpart.
          </p>
         </li>
        </ul>
        <p class="leafygreen-ui-1kp3ins">
         Use
         <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.updateZoneKeyRange" target="_self">
          <span>
           <code class="leafygreen-ui-1l06pbn">
            sh.updateZoneKeyRange()
           </code>
          </span>
         </a>
         to create the range for
         <code class="leafygreen-ui-1l06pbn">
          "facility": "FacilityAlpha"
         </code>
         :
        </p>
        <script class="structured_data" type="application/ld+json">
         {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.updateZoneKeyRange(\n   \"examples.metrics\",\n   { \"facility\": \"FacilityAlpha\", \"_id\" : MinKey },\n   { \"facility\": \"FacilityBaker\", \"_id\" : MinKey },\n   \"FacilityAlpha\"\n);","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">sh.<span class="lg-highlight-title lg-highlight-function">updateZoneKeyRange</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"examples.metrics"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-string">"facility"</span>: <span class="lg-highlight-string">"FacilityAlpha"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">MinKey</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-string">"facility"</span>: <span class="lg-highlight-string">"FacilityBaker"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">MinKey</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"FacilityAlpha"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">)<!-- -->;</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">
           Since zone range upper bounds are
           <em>
            exclusive
           </em>
           , this range only
covers documents with the distinct shard key prefix value
           <code class="leafygreen-ui-1l06pbn">
            "facilty" : "FacilityAlpha"
           </code>
           and all possible values of
           <code class="leafygreen-ui-1l06pbn">
            _id
           </code>
           .
          </p>
         </li>
        </ul>
        <p class="leafygreen-ui-1kp3ins">
         Use
         <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.updateZoneKeyRange" target="_self">
          <span>
           <code class="leafygreen-ui-1l06pbn">
            sh.updateZoneKeyRange()
           </code>
          </span>
         </a>
         to create the range for
         <code class="leafygreen-ui-1l06pbn">
          "facility": "FacilityBaker"
         </code>
         :
        </p>
        <script class="structured_data" type="application/ld+json">
         {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.updateZoneKeyRange(\n   \"examples.metrics\",\n   { \"facility\": \"FacilityBaker\", \"_id\" : MinKey },\n   { \"facility\": MaxKey, \"_id\" : MinKey },\n   \"FacilityBaker\"\n);","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">sh.<span class="lg-highlight-title lg-highlight-function">updateZoneKeyRange</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"examples.metrics"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-string">"facility"</span>: <span class="lg-highlight-string">"FacilityBaker"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">MinKey</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-string">"facility"</span>: <span class="lg-highlight-title lg-highlight-class">MaxKey</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">MinKey</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"FacilityBaker"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">)<!-- -->;</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">
           While the upper bound of this range can technically
capture other values of
           <code class="leafygreen-ui-1l06pbn">
            facility
           </code>
           , the initial chunk
distribution logic relies on the assumption that no other distinct
values for
           <code class="leafygreen-ui-1l06pbn">
            facility
           </code>
           exist. Since the collection only contains
documents where
           <code class="leafygreen-ui-1l06pbn">
            facility
           </code>
           is
           <code class="leafygreen-ui-1l06pbn">
            FacilityAlpha
           </code>
           or
           <code class="leafygreen-ui-1l06pbn">
            FacilityBaker
           </code>
           , this range only covers
documents with the distinct shard key prefix value
           <code class="leafygreen-ui-1l06pbn">
            "facility" : "FacilityBaker"
           </code>
           and all possible values of
           <code class="leafygreen-ui-1l06pbn">
            _id
           </code>
           .
          </p>
         </li>
        </ul>
       </section>
      </div>
     </div>
     <div class="css-1nuklj8 e1ckbxcu1">
      <div class="css-18fui5z e1ckbxcu0">
       <div class="css-19lsqsq e1ckbxcu2">
        3
       </div>
      </div>
      <div class="css-1ed38mk">
       <section>
        <h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
         Shard the Collection
         <a class="headerlink leafygreen-ui-1kepx47" href="#shard-the-collection-2" 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-the-collection-2">
          </div>
         </a>
        </h5>
        <div class="leafygreen-ui-15mdk4" role="note">
         <h2 class="leafygreen-ui-6n7b7d">
          Note
         </h2>
         <div class="leafygreen-ui-9mycqc">
          <p class="leafygreen-ui-1kp3ins">
           If the collection does not exist, the sharding operation creates
the collection.
          </p>
          <p class="leafygreen-ui-1kp3ins">
           If the collection is empty and no index exists to support the
shard key, the sharding operation creates the index.
          </p>
         </div>
        </div>
        <p class="leafygreen-ui-1kp3ins">
         Use
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection">
          <code class="leafygreen-ui-1l06pbn">
           sh.shardCollection()
          </code>
         </a>
         with
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#std-label-method-shard-collection-presplitHashedZones">
          presplitHashedZones: true
         </a>
         to shard the
collection and perform initial chunk creation and distribution:
        </p>
        <script class="structured_data" type="application/ld+json">
         {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.shardCollection(\n  \"examples.metrics\",\n  { \"facility\" : 1, \"_id\" : \"hashed\"},\n  false,\n  { presplitHashedZones: true }\n)","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">sh.<span class="lg-highlight-title lg-highlight-function">shardCollection</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-string">"examples.metrics"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"hashed"</span>}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->{ <span class="lg-highlight-attr">presplitHashedZones</span>: <span class="lg-highlight-literal">true</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</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>
       </section>
      </div>
     </div>
     <div class="css-1nuklj8 e1ckbxcu1">
      <div class="css-18fui5z e1ckbxcu0">
       <div class="css-19lsqsq e1ckbxcu2">
        4
       </div>
      </div>
      <div class="css-1ed38mk">
       <section>
        <h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
         Review the Created Chunks and Distribution
         <a class="headerlink leafygreen-ui-1kepx47" href="#review-the-created-chunks-and-distribution-2" 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="review-the-created-chunks-and-distribution-2">
          </div>
         </a>
        </h5>
        <p class="leafygreen-ui-1kp3ins">
         To see the created chunks and distribution, run the
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.status/#mongodb-method-sh.status">
          <code class="leafygreen-ui-1l06pbn">
           sh.status()
          </code>
         </a>
         operation:
        </p>
        <script class="structured_data" type="application/ld+json">
         {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.status()","programmingLanguage":"JavaScript"}
        </script>
        <div class="css-16lmvu9">
         <div class="leafygreen-ui-196mwvg">
          <div class="leafygreen-ui-yzcs8i">
           <pre class="leafygreen-ui-1q4bxgx" 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">sh.<span class="lg-highlight-title lg-highlight-function">status</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>
        <p class="leafygreen-ui-1kp3ins">
         The output resembles the following
(
         <em>
          content omitted for  readability
         </em>
         ):
        </p>
        <script class="structured_data" type="application/ld+json">
         {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"--- Sharding Status ---\n\n  databases:\n    { \"_id\" : \"config\", \"primary\" : \"config\" }\n    { \"_id\" : \"examples\", \"primary\" : \"shardA\", \"version\" : { \"uuid\" : UUID(\"6c351bcf-acd2-4fd9-82d8-9f6bd7321558\"), \"lastMod\" : 1 } }\n      examples.metrics\n        shard key: { \"facility\" : 1, \"_id\" : \"hashed\" }\n        unique: false\n        balancing: true\n        chunks:\n          shardA  3\n          shardB  3\n        { \"facility\" : { \"$minKey\" : 1 }, \"_id\" : { \"$minKey\" : 1 } } --&gt;&gt; { \"facility\" : \"FacilityAlpha\", \"_id\" : { \"$minKey\" : 1 } } on : shard1 Timestamp(1, 0)\n        { \"facility\" : \"FacilityAlpha\", \"_id\" : { \"$minKey\" : 1 } } --&gt;&gt; { \"facility\" : \"FacilityAlpha\", \"_id\" : NumberLong(0) } on : shard1 Timestamp(1, 1)\n        { \"facility\" : \"FacilityAlpha\", \"_id\" : NumberLong(0) } --&gt;&gt; { \"facility\" : \"FacilityBaker\", \"_id\" : { \"$minKey\" : 1 } } on : shard1 Timestamp(1, 2)\n        { \"facility\" : \"FacilityBaker\", \"_id\" : { \"$minKey\" : 1 } } --&gt;&gt; { \"facility\" : \"FacilityBaker\", \"_id\" : NumberLong(0) } on : shard2 Timestamp(1, 3)\n        { \"facility\" : \"FacilityBaker\", \"_id\" : NumberLong(0) } --&gt;&gt; { \"facility\" : { \"$maxKey\" : 1 }, \"_id\" : { \"$minKey\" : 1 } } on : shard2 Timestamp(1, 4)\n        { \"facility\" : { \"$maxKey\" : 1 }, \"_id\" : { \"$minKey\" : 1 } } --&gt;&gt; { \"facility\" : { \"$maxKey\" : 1 }, \"_id\" : { \"$maxKey\" : 1 } } on : shard2 Timestamp(1, 5)\n\n          tag: FacilityAlpha  { \"facility\" : \"FacilityAlpha\", \"_id\" : { \"$minKey\" : 1 } } --&gt;&gt; { \"facility\" : \"FacilityBaker\", \"_id\" : { \"$minKey\" : 1 } }\n          tag: FacilityBaker  { \"facility\" : \"FacilityBaker\", \"_id\" : { \"$minKey\" : 1 } } --&gt;&gt; { \"facility\" : { \"$maxKey\" : 1 }, \"_id\" : { \"$minKey\" : 1 } }","programmingLanguage":"JavaScript"}
        </script>
        <div class="css-16lmvu9">
         <div class="leafygreen-ui-196mwvg">
          <div class="leafygreen-ui-1b1bvay">
           <pre class="leafygreen-ui-11itue3" 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-title lg-highlight-class">Sharding</span> <span class="lg-highlight-title lg-highlight-class">Status</span> <!-- -->-<!-- -->-<!-- -->-</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-attr">databases</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"config"</span>, <span class="lg-highlight-string">"primary"</span> <!-- -->: <span class="lg-highlight-string">"config"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"examples"</span>, <span class="lg-highlight-string">"primary"</span> <!-- -->: <span class="lg-highlight-string">"shardA"</span>, <span class="lg-highlight-string">"version"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"uuid"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-function">UUID</span>(<span class="lg-highlight-string">"6c351bcf-acd2-4fd9-82d8-9f6bd7321558"</span>)<!-- -->, <span class="lg-highlight-string">"lastMod"</span> <!-- -->: <span class="lg-highlight-number">1</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      examples.<span class="lg-highlight-property">metrics</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">        shard <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"hashed"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">        <span class="lg-highlight-attr">unique</span>: <span class="lg-highlight-literal">false</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">        <span class="lg-highlight-attr">balancing</span>: <span class="lg-highlight-literal">true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">        <span class="lg-highlight-attr">chunks</span>:</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">          <!-- -->shardA  <span class="lg-highlight-number">3</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">          shardB  <span class="lg-highlight-number">3</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">        <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->&gt;&gt; <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityAlpha"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } on <!-- -->: <!-- -->shard1 <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">0</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">        <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityAlpha"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->&gt;&gt; <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityAlpha"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">0</span>) } on <!-- -->: <!-- -->shard1 <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">1</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">        <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityAlpha"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">0</span>) } <!-- -->-<!-- -->-<!-- -->&gt;&gt; <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityBaker"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } on <!-- -->: <!-- -->shard1 <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">2</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">        <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityBaker"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->&gt;&gt; <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityBaker"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">0</span>) } on <!-- -->: <!-- -->shard2 <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">3</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">        <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityBaker"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">0</span>) } <!-- -->-<!-- -->-<!-- -->&gt;&gt; <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$maxKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } on <!-- -->: <!-- -->shard2 <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">4</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">        <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$maxKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->&gt;&gt; <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$maxKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$maxKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } on <!-- -->: <!-- -->shard2 <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">5</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">          <span class="lg-highlight-attr">tag</span>: <span class="lg-highlight-title lg-highlight-class">FacilityAlpha</span>  <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityAlpha"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->&gt;&gt; <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityBaker"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } }</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">          <span class="lg-highlight-attr">tag</span>: <span class="lg-highlight-title lg-highlight-class">FacilityBaker</span>  <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityBaker"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->&gt;&gt; <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$maxKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</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>
        <p class="leafygreen-ui-1kp3ins">
         The sharding operation produced 6 chunks in total. Two chunks
correspond to the absolute lower and upper bounds. Two zones were
created, one on
         <code class="leafygreen-ui-1l06pbn">
          shardA
         </code>
         and one on
         <code class="leafygreen-ui-1l06pbn">
          shardB
         </code>
         , corresponding to
         <code class="leafygreen-ui-1l06pbn">
          FacilityAlpha
         </code>
         and
         <code class="leafygreen-ui-1l06pbn">
          FacilityBaker
         </code>
         . Each of these zones has been
further subdivided into 2 chunks using the hashed field.
        </p>
       </section>
      </div>
     </div>
    </div>
    <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">
      <ul class="leafygreen-ui-rioki0">
       <li class="leafygreen-ui-d7p7b6">
        <p class="leafygreen-ui-1kp3ins">
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addShardToZone/#mongodb-method-sh.addShardToZone">
          <code class="leafygreen-ui-1l06pbn">
           sh.addShardToZone()
          </code>
         </a>
        </p>
       </li>
       <li class="leafygreen-ui-d7p7b6">
        <p class="leafygreen-ui-1kp3ins">
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.removeRangeFromZone/#mongodb-method-sh.removeRangeFromZone">
          <code class="leafygreen-ui-1l06pbn">
           sh.removeRangeFromZone()
          </code>
         </a>
        </p>
       </li>
      </ul>
     </div>
    </div>
   </section>
  </section>
 </section>
</section>
