<section>
 <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
  sh.addTagRange()
  <a class="headerlink leafygreen-ui-1kepx47" href="#sh.addtagrange--" 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.addtagrange--">
   </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="#behavior" target="_self">
     <span>
      Behavior
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
     <span>
      Example
     </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.addTagRange(namespace, minimum, maximum, tag)
    </code>
    <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-sh.addTagRange" 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.addTagRange">
     </div>
    </a>
   </dt>
   <dd>
    <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 method aliases to
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#mongodb-method-sh.updateZoneKeyRange">
        <code class="leafygreen-ui-1l06pbn">
         sh.updateZoneKeyRange()
        </code>
       </a>
       . MongoDB provides
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding">
        Zone sharding
       </a>
       as the successor to tag-aware sharding.
      </p>
     </div>
    </div>
    <p class="leafygreen-ui-1kp3ins">
     Attaches a range of shard key values to a shard tag created using the
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addShardTag/#mongodb-method-sh.addShardTag">
      <code class="leafygreen-ui-1l06pbn">
       sh.addShardTag()
      </code>
     </a>
     method.
    </p>
    <p class="leafygreen-ui-1kp3ins">
     You can run
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/updateZoneKeyRange/#mongodb-dbcommand-dbcmd.updateZoneKeyRange">
      <code class="leafygreen-ui-1l06pbn">
       updateZoneKeyRange
      </code>
     </a>
     database command and its helpers
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#mongodb-method-sh.updateZoneKeyRange">
      <code class="leafygreen-ui-1l06pbn">
       sh.updateZoneKeyRange()
      </code>
     </a>
     and
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.addTagRange" target="_self">
      <span>
       <code class="leafygreen-ui-1l06pbn">
        sh.addTagRange()
       </code>
      </span>
     </a>
     on
an unsharded collection or a non-existing collection.
    </p>
    <p class="leafygreen-ui-1kp3ins">
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.addTagRange" target="_self">
      <span>
       <code class="leafygreen-ui-1l06pbn">
        sh.addTagRange()
       </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>
           The
           <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-namespace">
            namespace
           </a>
           of the sharded collection to tag.
          </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>
           The minimum value of the
           <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key">
            shard key
           </a>
           range to include in the
tag. The minimum is an inclusive match. Specify the minimum value in
the form of
           <code class="leafygreen-ui-1l06pbn">
            &lt;fieldname&gt;:&lt;value&gt;
           </code>
           .  This value must be of the same
BSON type or types as the shard key.
          </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>
           The maximum value of the shard key range to include in the tag.
The maximum is an exclusive match.  Specify the maximum value in the
form of
           <code class="leafygreen-ui-1l06pbn">
            &lt;fieldname&gt;:&lt;value&gt;
           </code>
           . This value must be of the same BSON
type or types as the shard key.
          </div>
         </div>
        </td>
       </tr>
       <tr class="">
        <td class="leafygreen-ui-1drjk7h">
         <div class="leafygreen-ui-1n4j8xf">
          <div>
           <code class="leafygreen-ui-1l06pbn">
            tag
           </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 tag to attach the range specified by the
           <code class="leafygreen-ui-1l06pbn">
            minimum
           </code>
           and
           <code class="leafygreen-ui-1l06pbn">
            maximum
           </code>
           arguments to.
          </div>
         </div>
        </td>
       </tr>
      </tbody>
     </table>
    </div>
    <p class="leafygreen-ui-1kp3ins">
     Use
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addShardTag/#mongodb-method-sh.addShardTag">
      <code class="leafygreen-ui-1l06pbn">
       sh.addShardTag()
      </code>
     </a>
     to ensure that the balancer migrates
documents that exist within the specified range to a specific shard
or set of shards.
    </p>
    <p class="leafygreen-ui-1kp3ins">
     Only issue
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.addTagRange" target="_self">
      <span>
       <code class="leafygreen-ui-1l06pbn">
        sh.addTagRange()
       </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">
   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>
  <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>
   <span class="leafygreen-ui-1qnjd6d" id="std-label-addTagRange-method-init-chunk-distribution">
   </span>
  </section>
  <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.addTagRange" target="_self">
     <span>
      <code class="leafygreen-ui-1l06pbn">
       sh.addTagRange()
      </code>
     </span>
    </a>
    to create the zones and zone ranges
    <em>
     before
    </em>
    sharding the collection.
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="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#std-label-pre-define-zone-range-example">
     Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection
     <!-- -->
     .
    </a>
   </p>
   <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="_x8xi1n3n4" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_rj8k7nuw5" name="" role="tab" tabindex="0">
        <div class="leafygreen-ui-1nxuzmg">
         Hashed Field Is Prefix
        </div>
       </button>
       <button aria-controls="_vd85ks8e8" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_vekhwjfu6" 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="_bpiajo6nr" class="" id="_ipbxcibuw" 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="_yi2t90nxx" class="leafygreen-ui-38lglc" id="_01rfg1qw8" 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="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#std-label-pre-define-zone-range-hashed-example">
      Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection
      <!-- -->
      .
     </a>
    </p>
   </section>
  </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>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Example
   <a class="headerlink leafygreen-ui-1kepx47" href="#example" 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="example">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   Given a shard key of
   <code class="leafygreen-ui-1l06pbn">
    {state: 1, zip: 1}
   </code>
   , the following operation
creates a tag range covering zip codes in New York State:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.addTagRange( \"exampledb.collection\",\n                { state: \"NY\", zip: MinKey },\n                { state: \"NY\", zip: MaxKey },\n                \"NY\"\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">addTagRange</span>( <span class="lg-highlight-string">"exampledb.collection"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                <!-- -->{ <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"NY"</span>, <span class="lg-highlight-attr">zip</span>: <span class="lg-highlight-title lg-highlight-class">MinKey</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                <!-- -->{ <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"NY"</span>, <span class="lg-highlight-attr">zip</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">"NY"</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>
</section>
