<section>
 <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
  shardCollection
  <a class="headerlink leafygreen-ui-1kepx47" href="#shardcollection" 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="shardcollection">
   </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="#syntax" target="_self">
     <span>
      Syntax
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#command-fields" target="_self">
     <span>
      Command Fields
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#considerations" target="_self">
     <span>
      Considerations
     </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="dbcommand">
   <dt>
    <code class="leafygreen-ui-1l06pbn">
     shardCollection
    </code>
    <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.shardCollection" 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-dbcommand-dbcmd.shardCollection">
     </div>
    </a>
   </dt>
   <dd>
    <p class="leafygreen-ui-1kp3ins">
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/sharding/#std-label-sharding-background">
      Shards
     </a>
     a collection to distribute its documents across
shards. The
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.shardCollection" target="_self">
      <span>
       <code class="leafygreen-ui-1l06pbn">
        shardCollection
       </code>
      </span>
     </a>
     command must be run against the
     <code class="leafygreen-ui-1l06pbn">
      admin
     </code>
     database.
    </p>
    <div class="leafygreen-ui-15mdk4" role="note">
     <h2 class="leafygreen-ui-6n7b7d">
      Note
     </h2>
     <div class="leafygreen-ui-9mycqc">
      <div>
       <p>
        <em>
         Changed
         <!-- -->
         in version
         <!-- -->
         6.0
        </em>
        .
       </p>
      </div>
      <p class="leafygreen-ui-1kp3ins">
       Starting in MongoDB 6.0, sharding a collection does
       <strong>
        not
       </strong>
       require you to
first run the
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/enableSharding/#mongodb-dbcommand-dbcmd.enableSharding">
        <code class="leafygreen-ui-1l06pbn">
         enableSharding
        </code>
       </a>
       command to configure the database.
      </p>
     </div>
    </div>
    <div class="leafygreen-ui-13vw3ie" role="note">
     <h2 class="leafygreen-ui-1fn4p2b">
      Tip
     </h2>
     <div class="leafygreen-ui-9mycqc">
      <p class="leafygreen-ui-1kp3ins">
       In
       <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self">
        <span>
         <code class="leafygreen-ui-1l06pbn">
          mongosh
         </code>
        </span>
       </a>
       , this command can also be run through the
       <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>
       helper method
       <!-- -->
       .
      </p>
      <p class="leafygreen-ui-1kp3ins">
       Helper methods are convenient for
       <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#std-program-mongosh" target="_self">
        <span>
         <code class="leafygreen-ui-1l06pbn">
          mongosh
         </code>
        </span>
       </a>
       users, but they may not
return the same level of information as database commands.  In cases where
the convenience is not needed or the additional return fields are required,
use the database command.
      </p>
     </div>
    </div>
   </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 command 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">
   Syntax
   <a class="headerlink leafygreen-ui-1kepx47" href="#syntax" 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="syntax">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   To run
   <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.shardCollection" target="_self">
    <span>
     <code class="leafygreen-ui-1l06pbn">
      shardCollection
     </code>
    </span>
   </a>
   , use the
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.runCommand/#mongodb-method-db.runCommand">
    <code class="leafygreen-ui-1l06pbn">
     db.runCommand( { &lt;command&gt; } )
    </code>
   </a>
   method.
  </p>
  <p class="leafygreen-ui-1kp3ins">
   The command has the following form:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n   {\n     shardCollection: \"&lt;database&gt;.&lt;collection&gt;\",\n     key: { &lt;field1&gt;: &lt;1|\"hashed\"&gt;, ... },\n     unique: &lt;boolean&gt;,\n     numInitialChunks: &lt;integer&gt;,\n     presplitHashedZones: &lt;boolean&gt;,\n     collation: { locale: \"simple\" },\n     timeseries: &lt;object&gt;\n   }\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">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">     <span class="lg-highlight-attr">shardCollection</span>: <span class="lg-highlight-string">"&lt;database&gt;.&lt;collection&gt;"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">     <span class="lg-highlight-attr">key</span>: <!-- -->{ &lt;<!-- -->field1<!-- -->&gt;<!-- -->: <!-- -->&lt;1|"hashed"&gt;, ... },</td></tr><tr class=""><td class="leafygreen-ui-7razhx">     unique: &lt;boolean&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">     numInitialChunks: &lt;integer&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">     presplitHashedZones: &lt;boolean&gt;,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">     collation: { locale: "simple" },</td></tr><tr class=""><td class="leafygreen-ui-7razhx">     timeseries: &lt;object&gt;</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   }</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>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Command Fields
   <a class="headerlink leafygreen-ui-1kepx47" href="#command-fields" 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="command-fields">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   The command takes the following fields:
  </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>
         Field
        </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="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <code class="leafygreen-ui-1l06pbn">
          shardCollection
         </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 collection to shard in the form
         <code class="leafygreen-ui-1l06pbn">
          &lt;database&gt;.&lt;collection&gt;
         </code>
         .
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <code class="leafygreen-ui-1l06pbn">
          key
         </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 document that specifies the field or fields to use as the
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-sharding-shard-key">
           shard key
           <!-- -->
           .
          </a>
         </p>
         <p class="leafygreen-ui-1kp3ins">
          <code class="leafygreen-ui-1l06pbn">
           { &lt;field1&gt;: &lt;1|"hashed"&gt;, ... }
          </code>
         </p>
         <p class="leafygreen-ui-1kp3ins">
          Set the field values to either:
         </p>
         <ul class="leafygreen-ui-rioki0">
          <li class="leafygreen-ui-d7p7b6">
           <p class="leafygreen-ui-1kp3ins">
            <code class="leafygreen-ui-1l06pbn">
             1
            </code>
            for
            <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/ranged-sharding/#std-label-sharding-ranged">
             range-based sharding
            </a>
           </p>
          </li>
          <li class="leafygreen-ui-d7p7b6">
           <p class="leafygreen-ui-1kp3ins">
            <code class="leafygreen-ui-1l06pbn">
             "hashed"
            </code>
            to specify a
            <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-hashed-shard-keys" target="_self">
             <span>
              hashed shard key
              <!-- -->
              .
             </span>
            </a>
           </p>
          </li>
         </ul>
         <p class="leafygreen-ui-1kp3ins">
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-sharding-shard-key">
           shard key
          </a>
          must be
supported by an index. Unless the collection is empty, the
index must exist prior to the
          <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.shardCollection" target="_self">
           <span>
            <code class="leafygreen-ui-1l06pbn">
             shardCollection
            </code>
           </span>
          </a>
          command. If the collection is empty, MongoDB creates the
index prior to sharding the collection if the index that can
support the shard key does not already exist.
         </p>
         <p class="leafygreen-ui-1kp3ins">
          See also
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-sharding-shard-key-indexes">
           Shard Key Indexes
          </a>
         </p>
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <code class="leafygreen-ui-1l06pbn">
          unique
         </code>
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         boolean
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <p class="leafygreen-ui-1kp3ins">
          Specify
          <code class="leafygreen-ui-1l06pbn">
           true
          </code>
          to ensure that the underlying index
enforces a unique constraint. Defaults to
          <code class="leafygreen-ui-1l06pbn">
           false
          </code>
          .
         </p>
         <p class="leafygreen-ui-1kp3ins">
          You cannot specify
          <code class="leafygreen-ui-1l06pbn">
           true
          </code>
          when using
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/hashed-sharding/#std-label-sharding-hashed">
           hashed shard keys
           <!-- -->
           .
          </a>
         </p>
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <code class="leafygreen-ui-1l06pbn">
          numInitialChunks
         </code>
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         integer
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <p class="leafygreen-ui-1kp3ins">
          Specifies the initial number of chunks to create across all shards in
the cluster when sharding an
          <em>
           empty
          </em>
          collection with a
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/hashed-sharding/#std-label-sharding-hashed-sharding">
           hashed shard key
          </a>
          . MongoDB
will then create and balance chunks across the cluster. The
          <code class="leafygreen-ui-1l06pbn">
           numInitialChunks
          </code>
          must result in less than
          <code class="leafygreen-ui-1l06pbn">
           8192
          </code>
          per shard.
         </p>
         <p class="leafygreen-ui-1kp3ins">
          If the collection is not empty or the shard key does not
contain a hashed field, the operation returns an error.
         </p>
         <ul class="leafygreen-ui-rioki0">
          <li class="leafygreen-ui-d7p7b6">
           <p class="leafygreen-ui-1kp3ins">
            If sharding with
            <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cmd-shard-collection-presplitHashedZones" target="_self">
             <span>
              presplitHashedZones: true
             </span>
            </a>
            ,
MongoDB attempts to evenly distribute the specified
number of chunks across the zones in the cluster.
           </p>
          </li>
          <li class="leafygreen-ui-d7p7b6">
           <p class="leafygreen-ui-1kp3ins">
            If sharding with
            <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cmd-shard-collection-presplitHashedZones" target="_self">
             <span>
              presplitHashedZones: false
             </span>
            </a>
            or omitted and
no zones and zone ranges are defined for the empty
collection, MongoDB attempts to evenly distributed the
specified number of chunks across the shards in the cluster.
           </p>
          </li>
          <li class="leafygreen-ui-d7p7b6">
           <p class="leafygreen-ui-1kp3ins">
            If sharding with
            <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cmd-shard-collection-presplitHashedZones" target="_self">
             <span>
              presplitHashedZones: false
             </span>
            </a>
            or omitted and
zones and zone ranges have been defined for the empty
collection,
            <code class="leafygreen-ui-1l06pbn">
             numInitialChunks
            </code>
            has no effect.
           </p>
          </li>
         </ul>
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <code class="leafygreen-ui-1l06pbn">
          collation
         </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>
         Optional. If the collection specified to
         <code class="leafygreen-ui-1l06pbn">
          shardCollection
         </code>
         has a default
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation">
          collation
         </a>
         , you
         <em>
          must
         </em>
         include a
collation document with
         <code class="leafygreen-ui-1l06pbn">
          { locale : "simple" }
         </code>
         , or the
         <code class="leafygreen-ui-1l06pbn">
          shardCollection
         </code>
         command fails. At least one of the indexes
whose fields support the shard key pattern must have the simple
collation.
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cmd-shard-collection-presplitHashedZones" target="_self">
          <span>
           presplitHashedZones
          </span>
         </a>
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         boolean
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <span class="leafygreen-ui-1qnjd6d" id="std-label-cmd-shard-collection-presplitHashedZones">
         </span>
         <p class="leafygreen-ui-1kp3ins">
          Optional. Specify
          <code class="leafygreen-ui-1l06pbn">
           true
          </code>
          to perform initial chunk creation
and distribution for an empty or non-existing collection based
on the defined zones and zone ranges for the collection. For
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/hashed-sharding/#std-label-sharding-hashed">
           hashed sharding
          </a>
          only.
         </p>
         <p class="leafygreen-ui-1kp3ins">
          <code class="leafygreen-ui-1l06pbn">
           shardCollection
          </code>
          with
          <code class="leafygreen-ui-1l06pbn">
           presplitHashedZones: true
          </code>
          returns
an error if any of the following are true:
         </p>
         <ul class="leafygreen-ui-rioki0">
          <li class="leafygreen-ui-d7p7b6">
           <p class="leafygreen-ui-1kp3ins">
            The shard key does not contain a hashed field
(i.e. is not a
            <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/#std-label-index-hashed-index">
             single field hashed index
            </a>
            or
            <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/create/#std-label-index-type-compound-hashed">
             compound hashed index
            </a>
            ).
           </p>
          </li>
          <li class="leafygreen-ui-d7p7b6">
           <p class="leafygreen-ui-1kp3ins">
            The collection has no defined zones or zone ranges.
           </p>
          </li>
          <li class="leafygreen-ui-d7p7b6">
           <p class="leafygreen-ui-1kp3ins">
            The defined zone range or ranges do not meet the
            <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-shardCollection-zones" target="_self">
             <span>
              requirements
              <!-- -->
              .
             </span>
            </a>
           </p>
          </li>
         </ul>
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cmd-shard-collection-timeseries" target="_self">
          <span>
           timeseries
          </span>
         </a>
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         object
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <span class="leafygreen-ui-1qnjd6d" id="std-label-cmd-shard-collection-timeseries">
         </span>
         <p class="leafygreen-ui-1kp3ins">
          Optional. Specify this option to create a new sharded
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-manual-timeseries-collection">
           time series
collection
           <!-- -->
           .
          </a>
         </p>
         <p class="leafygreen-ui-1kp3ins">
          To shard an existing time series collection, omit this parameter.
         </p>
         <p class="leafygreen-ui-1kp3ins">
          When the collection specified to
          <code class="leafygreen-ui-1l06pbn">
           shardCollection
          </code>
          is a time series
collection and the
          <code class="leafygreen-ui-1l06pbn">
           timeseries
          </code>
          option is not specified, MongoDB uses
the values that define the existing time series collection to populate
the
          <code class="leafygreen-ui-1l06pbn">
           timeseries
          </code>
          field.
         </p>
         <p class="leafygreen-ui-1kp3ins">
          For detailed syntax, see
          <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cmd-sharded-time-series-collection-options" target="_self">
           <span>
            Time Series Options
            <!-- -->
            .
           </span>
          </a>
         </p>
         <div>
          <p>
           <em>
            New
            <!-- -->
            in version
            <!-- -->
            5.1
           </em>
           .
          </p>
         </div>
        </div>
       </div>
      </td>
     </tr>
    </tbody>
   </table>
  </div>
  <span class="leafygreen-ui-1qnjd6d" id="std-label-cmd-sharded-time-series-collection-options">
  </span>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Time Series Options
    <a class="headerlink leafygreen-ui-1kepx47" href="#time-series-options" 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="time-series-options">
     </div>
    </a>
   </h3>
   <div>
    <p>
     <em>
      New
      <!-- -->
      in version
      <!-- -->
      5.1
     </em>
     .
    </p>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    To create a new
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-manual-timeseries-collection">
     time series collection
    </a>
    that is sharded, specify the
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cmd-shard-collection-timeseries" target="_self">
     <span>
      timeseries
     </span>
    </a>
    option to
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.shardCollection" target="_self">
     <span>
      <code class="leafygreen-ui-1l06pbn">
       shardCollection
      </code>
      .
     </span>
    </a>
   </p>
   <p class="leafygreen-ui-1kp3ins">
    The
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cmd-shard-collection-timeseries" target="_self">
     <span>
      timeseries
     </span>
    </a>
    option takes
the following fields:
   </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>
          Field
         </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">
           timeField
          </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">
           Required. The name of the field which contains the date in each
time series document. Documents in a time series collection must
have a valid BSON date as the value for the
           <code class="leafygreen-ui-1l06pbn">
            timeField
           </code>
           .
          </p>
          <p class="leafygreen-ui-1kp3ins">
           Starting in MongoDB 8.0, use of the
           <code class="leafygreen-ui-1l06pbn">
            timeField
           </code>
           as a shard key in a
time series collection is deprecated.
          </p>
         </div>
        </div>
       </td>
      </tr>
      <tr class="">
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          <code class="leafygreen-ui-1l06pbn">
           metaField
          </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">
           Optional. The name of the field which contains metadata in
each time series document. The metadata in the specified field
should be data that is used to label a unique series of
documents. The metadata should rarely, if ever, change
The name of the specified field may not be
           <code class="leafygreen-ui-1l06pbn">
            _id
           </code>
           or the same
as the
           <code class="leafygreen-ui-1l06pbn">
            timeseries.timeField
           </code>
           . The field can be of any data type.
          </p>
          <p class="leafygreen-ui-1kp3ins">
           Although the
           <code class="leafygreen-ui-1l06pbn">
            metaField
           </code>
           field is optional, using metadata can improve
query optimization. For example, MongoDB automatically
           <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries/timeseries-secondary-index/#std-label-timeseries-add-secondary-index">
            creates a compound index
           </a>
           on the
           <code class="leafygreen-ui-1l06pbn">
            metaField
           </code>
           and
           <code class="leafygreen-ui-1l06pbn">
            timeField
           </code>
           fields for new collections.
If you do not provide a value for this field, the data is bucketed solely
based on time.
          </p>
         </div>
        </div>
       </td>
      </tr>
      <tr class="">
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          <code class="leafygreen-ui-1l06pbn">
           granularity
          </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">
           Optional. Possible values are:
          </p>
          <ul class="leafygreen-ui-rioki0">
           <li class="leafygreen-ui-d7p7b6">
            <p class="leafygreen-ui-1kp3ins">
             <code class="leafygreen-ui-1l06pbn">
              "seconds"
             </code>
            </p>
           </li>
           <li class="leafygreen-ui-d7p7b6">
            <p class="leafygreen-ui-1kp3ins">
             <code class="leafygreen-ui-1l06pbn">
              "minutes"
             </code>
            </p>
           </li>
           <li class="leafygreen-ui-d7p7b6">
            <p class="leafygreen-ui-1kp3ins">
             <code class="leafygreen-ui-1l06pbn">
              "hours"
             </code>
            </p>
           </li>
          </ul>
          <p class="leafygreen-ui-1kp3ins">
           By default, MongoDB sets the
           <code class="leafygreen-ui-1l06pbn">
            granularity
           </code>
           to
           <code class="leafygreen-ui-1l06pbn">
            "seconds"
           </code>
           for
high-frequency ingestion.
          </p>
          <p class="leafygreen-ui-1kp3ins">
           Manually set the
           <code class="leafygreen-ui-1l06pbn">
            granularity
           </code>
           parameter to improve performance
by optimizing how data in the time series collection is stored
internally. To select a value for
           <code class="leafygreen-ui-1l06pbn">
            granularity
           </code>
           , choose the
closest match to the time span between consecutive incoming
measurements.
          </p>
          <p class="leafygreen-ui-1kp3ins">
           If you specify the
           <code class="leafygreen-ui-1l06pbn">
            timeseries.metaField
           </code>
           , consider the time
span between consecutive incoming measurements that have the same
unique value for the
           <code class="leafygreen-ui-1l06pbn">
            metaField
           </code>
           field. Measurements often have
the same unique value for the
           <code class="leafygreen-ui-1l06pbn">
            metaField
           </code>
           field if they come
from the same source.
          </p>
          <p class="leafygreen-ui-1kp3ins">
           If you do not specify
           <code class="leafygreen-ui-1l06pbn">
            timeseries.metaField
           </code>
           , consider the time
span between all measurements that are inserted in the collection.
          </p>
          <p class="leafygreen-ui-1kp3ins">
           If you set the
           <code class="leafygreen-ui-1l06pbn">
            granularity
           </code>
           parameter, you can't set the
           <code class="leafygreen-ui-1l06pbn">
            bucketMaxSpanSeconds
           </code>
           and
           <code class="leafygreen-ui-1l06pbn">
            bucketRoundingSeconds
           </code>
           parameters.
          </p>
         </div>
        </div>
       </td>
      </tr>
     </tbody>
    </table>
   </div>
  </section>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Considerations
   <a class="headerlink leafygreen-ui-1kepx47" href="#considerations" 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="considerations">
    </div>
   </a>
  </h2>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Shard Keys
    <a class="headerlink leafygreen-ui-1kepx47" href="#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="shard-keys">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    While you can
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-change-a-shard-key/#std-label-change-a-shard-key">
     change your shard key
    </a>
    later, it is important to carefully consider your shard key choice to
avoid scalability and perfomance issues.
   </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">
     <ul class="leafygreen-ui-rioki0">
      <li class="leafygreen-ui-d7p7b6">
       <p class="leafygreen-ui-1kp3ins">
        <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-sharding-shard-key-selection">
         Choose a Shard Key
        </a>
       </p>
      </li>
      <li class="leafygreen-ui-d7p7b6">
       <p class="leafygreen-ui-1kp3ins">
        <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-sharding-shard-key">
         Shard Keys
        </a>
       </p>
      </li>
     </ul>
    </div>
   </div>
   <section>
    <h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
     Shard Keys on Time Series Collections
     <a class="headerlink leafygreen-ui-1kepx47" href="#shard-keys-on-time-series-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="shard-keys-on-time-series-collections">
      </div>
     </a>
    </h4>
    <p class="leafygreen-ui-1kp3ins">
     When sharding time series collections, you can only specify
the following fields in the shard key:
    </p>
    <ul class="leafygreen-ui-rioki0">
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       The
       <code class="leafygreen-ui-1l06pbn">
        metaField
       </code>
      </p>
     </li>
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       Sub-fields of
       <code class="leafygreen-ui-1l06pbn">
        metaField
       </code>
      </p>
     </li>
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       The
       <code class="leafygreen-ui-1l06pbn">
        timeField
       </code>
      </p>
     </li>
    </ul>
    <p class="leafygreen-ui-1kp3ins">
     You may specify combinations of these fields in the shard key. No other
fields, including
     <code class="leafygreen-ui-1l06pbn">
      _id
     </code>
     , are allowed in the shard key pattern.
    </p>
    <p class="leafygreen-ui-1kp3ins">
     When you specify the shard key:
    </p>
    <ul class="leafygreen-ui-rioki0">
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       <code class="leafygreen-ui-1l06pbn">
        metaField
       </code>
       can be either a:
      </p>
      <ul class="leafygreen-ui-rioki0">
       <li class="leafygreen-ui-d7p7b6">
        <p class="leafygreen-ui-1kp3ins">
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/hashed-sharding/#std-label-sharding-hashed-sharding">
          Hashed shard key
         </a>
        </p>
       </li>
       <li class="leafygreen-ui-d7p7b6">
        <p class="leafygreen-ui-1kp3ins">
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/ranged-sharding/#std-label-sharding-ranged">
          Ranged shard key
         </a>
        </p>
       </li>
      </ul>
     </li>
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       <code class="leafygreen-ui-1l06pbn">
        timeField
       </code>
       must be:
      </p>
      <ul class="leafygreen-ui-rioki0">
       <li class="leafygreen-ui-d7p7b6">
        <p class="leafygreen-ui-1kp3ins">
         A
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/ranged-sharding/#std-label-sharding-ranged">
          ranged shard key
         </a>
        </p>
       </li>
       <li class="leafygreen-ui-d7p7b6">
        <p class="leafygreen-ui-1kp3ins">
         At the end of the shard key pattern
        </p>
       </li>
      </ul>
     </li>
    </ul>
    <div class="leafygreen-ui-13vw3ie" role="note">
     <h2 class="leafygreen-ui-1fn4p2b">
      Tip
     </h2>
     <div class="leafygreen-ui-9mycqc">
      <p class="leafygreen-ui-1kp3ins">
       Avoid specifying
       <strong>
        only
       </strong>
       the
       <code class="leafygreen-ui-1l06pbn">
        timeField
       </code>
       as the shard key. Since
the
       <code class="leafygreen-ui-1l06pbn">
        timeField
       </code>
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-shard-key-monotonic">
        increases monotonically
       </a>
       , it may result in all writes appearing on a
single chunk within the cluster. Ideally, data is evenly distributed
across chunks.
      </p>
      <p class="leafygreen-ui-1kp3ins">
       To learn how to best choose a shard key, see:
      </p>
      <ul class="leafygreen-ui-rioki0">
       <li class="leafygreen-ui-d7p7b6">
        <p class="leafygreen-ui-1kp3ins">
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-sharding-shard-key-requirements">
          Choose a Shard Key
         </a>
        </p>
       </li>
       <li class="leafygreen-ui-d7p7b6">
        <p class="leafygreen-ui-1kp3ins">
         <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/blog/post/on-selecting-a-shard-key-for-mongodb?tck=docs_server" target="_self">
          <span>
           MongoDB Blog: On Selecting a Shard Key for MongoDB
           <!-- -->
           .
          </span>
         </a>
        </p>
       </li>
      </ul>
     </div>
    </div>
    <p class="leafygreen-ui-1kp3ins">
     Starting in MongoDB 8.0, use of the
     <code class="leafygreen-ui-1l06pbn">
      timeField
     </code>
     as a shard key in a
time series collection is deprecated.
    </p>
    <span class="leafygreen-ui-1qnjd6d" id="std-label-hashed-shard-keys">
    </span>
   </section>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Hashed Shard Keys
    <a class="headerlink leafygreen-ui-1kepx47" href="#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="hashed-shard-keys">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/hashed-sharding/#std-label-sharding-hashed-sharding">
     Hashed shard keys
    </a>
    use a
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/#std-label-index-type-hashed">
     hashed index
    </a>
    or a
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/create/#std-label-index-type-compound-hashed">
     compound hashed index
    </a>
    as the shard key.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    Use the form
    <code class="leafygreen-ui-1l06pbn">
     field: "hashed"
    </code>
    to specify a hashed shard key field.
   </p>
   <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 chunk migrations are in progress while creating a hashed
shard key collection, the initial chunk distribution may be
uneven until the balancer automatically balances the
collection.
     </p>
    </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">
     <p class="leafygreen-ui-1kp3ins">
      <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/hashed-sharding/">
       Hashed Sharding
      </a>
     </p>
    </div>
   </div>
   <span class="leafygreen-ui-1qnjd6d" id="std-label-shardCollection-zones">
   </span>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Zone Sharding and Initial Chunk Distribution
    <a class="headerlink leafygreen-ui-1kepx47" href="#zone-sharding-and-initial-chunk-distribution" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="zone-sharding-and-initial-chunk-distribution">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    The shard collection operation (i.e.
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.shardCollection" target="_self">
     <span>
      <code class="leafygreen-ui-1l06pbn">
       shardCollection
      </code>
     </span>
    </a>
    command and the
    <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>
    helper) can perform
initial chunk creation and distribution for an empty or a
non-existing collection if
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/">
     zones and zone ranges
    </a>
    have been defined for the collection. Initial
chunk distribution allows for a faster setup of zoned sharding.
After the initial distribution, the balancer manages the chunk
distribution going forward per usual.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    See
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#std-label-pre-define-zone-range-example">
     Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection
    </a>
    for an example. If sharding a
collection using a ranged or single-field hashed shard key, the
    <code class="leafygreen-ui-1l06pbn">
     numInitialChunks
    </code>
    option has no effect if zones and zone ranges have
been defined for the empty collection.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    To shard a collection using a
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/create/#std-label-index-type-compound-hashed">
     compound hashed index
    </a>
    , see
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-shardCollection-zones-compound-hashed" target="_self">
     <span>
      Zone Sharding and Compound Hashed Indexes
      <!-- -->
      .
     </span>
    </a>
   </p>
   <span class="leafygreen-ui-1qnjd6d" id="std-label-shardCollection-zones-compound-hashed">
   </span>
   <section>
    <h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
     Zone Sharding and Compound Hashed Indexes
     <a class="headerlink leafygreen-ui-1kepx47" href="#zone-sharding-and-compound-hashed-indexes" 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="zone-sharding-and-compound-hashed-indexes">
      </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>
     . When
sharding an empty or non-existing collection using a compound hashed
shard key, additional requirements apply in order for MongoDB to
perform initial chunk creation and distribution.
    </p>
    <p class="leafygreen-ui-1kp3ins">
     The
     <code class="leafygreen-ui-1l06pbn">
      numInitialChunks
     </code>
     option has no effect if zones and zone ranges
have been defined for the empty collection
     <em>
      and
     </em>
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-cmd-shard-collection-presplitHashedZones" target="_self">
      <span>
       presplitHashedZones
      </span>
     </a>
     is
     <code class="leafygreen-ui-1l06pbn">
      false
     </code>
     .
    </p>
    <p class="leafygreen-ui-1kp3ins">
     See
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#std-label-pre-define-zone-range-hashed-example">
      Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection
     </a>
     for an example.
    </p>
    <div class="leafygreen-ui-13vw3ie" role="note">
     <h2 class="leafygreen-ui-1fn4p2b">
      Tip
     </h2>
     <h3 class="leafygreen-ui-144d5kf">
      <strong>
       See also:
      </strong>
     </h3>
     <div class="leafygreen-ui-9mycqc">
      <ul class="leafygreen-ui-rioki0">
       <li class="leafygreen-ui-d7p7b6">
        <p class="leafygreen-ui-1kp3ins">
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-initial-chunks">
          Initial Chunks
         </a>
        </p>
       </li>
       <li class="leafygreen-ui-d7p7b6">
        <p class="leafygreen-ui-1kp3ins">
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/balancerCollectionStatus/#mongodb-dbcommand-dbcmd.balancerCollectionStatus">
          <code class="leafygreen-ui-1l06pbn">
           balancerCollectionStatus
          </code>
         </a>
        </p>
       </li>
      </ul>
     </div>
    </div>
   </section>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Uniqueness
    <a class="headerlink leafygreen-ui-1kepx47" href="#uniqueness" 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="uniqueness">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    If specifying
    <code class="leafygreen-ui-1l06pbn">
     unique: true
    </code>
    :
   </p>
   <ul class="leafygreen-ui-rioki0">
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      If the collection is empty,
      <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.shardCollection" target="_self">
       <span>
        <code class="leafygreen-ui-1l06pbn">
         shardCollection
        </code>
       </span>
      </a>
      creates the unique index on the
shard key if such an index does not already exist.
     </p>
    </li>
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      If the collection is not empty, you must create the index first
before using
      <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.shardCollection" target="_self">
       <span>
        <code class="leafygreen-ui-1l06pbn">
         shardCollection
        </code>
        .
       </span>
      </a>
     </p>
    </li>
   </ul>
   <p class="leafygreen-ui-1kp3ins">
    Although you can have a unique
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-compound-index">
     compound index
    </a>
    where the shard
key is a
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-compound/#std-label-compound-index-prefix">
     prefix
    </a>
    , if using
    <code class="leafygreen-ui-1l06pbn">
     unique
    </code>
    parameter, the collection must have a unique index that is on the shard
key.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    See also
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-sharding-shard-key-unique">
     Sharded Collection and Unique Indexes
    </a>
   </p>
   <section>
    <h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
     Collation
     <a class="headerlink leafygreen-ui-1kepx47" href="#collation" 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="collation">
      </div>
     </a>
    </h4>
    <p class="leafygreen-ui-1kp3ins">
     If the collection has a default
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation">
      collation
     </a>
     ,
the
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.shardCollection" target="_self">
      <span>
       <code class="leafygreen-ui-1l06pbn">
        shardCollection
       </code>
      </span>
     </a>
     command must include a
     <code class="leafygreen-ui-1l06pbn">
      collation
     </code>
     parameter with the
value
     <code class="leafygreen-ui-1l06pbn">
      { locale: "simple" }
     </code>
     . For non-empty collections with a
default collation, you must have at least one index with the simple
collation whose fields support the shard key pattern.
    </p>
    <p class="leafygreen-ui-1kp3ins">
     You do not need to specify the
     <code class="leafygreen-ui-1l06pbn">
      collation
     </code>
     option for collections
without a collation. If you do specify the collation option for
a collection with no collation, it will have no effect.
    </p>
   </section>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Write Concern
    <a class="headerlink leafygreen-ui-1kepx47" href="#write-concern" 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="write-concern">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
     <code class="leafygreen-ui-1l06pbn">
      mongos
     </code>
    </a>
    uses
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
     <code class="leafygreen-ui-1l06pbn">
      "majority"
     </code>
    </a>
    for the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
     write concern
    </a>
    of the
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.shardCollection" target="_self">
     <span>
      <code class="leafygreen-ui-1l06pbn">
       shardCollection
      </code>
     </span>
    </a>
    command, its helper
    <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>
    , and the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardAndDistributeCollection/#mongodb-method-sh.shardAndDistributeCollection">
     <code class="leafygreen-ui-1l06pbn">
      sh.shardAndDistributeCollection()
     </code>
    </a>
    method.
   </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">
   The following operation enables sharding for the
   <code class="leafygreen-ui-1l06pbn">
    people
   </code>
   collection
in the
   <code class="leafygreen-ui-1l06pbn">
    records
   </code>
   database and uses the
   <code class="leafygreen-ui-1l06pbn">
    zipcode
   </code>
   field as the
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-shard-key">
    shard key
    <!-- -->
    :
   </a>
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { shardCollection: \"records.people\", key: { zipcode: 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">db.<span class="lg-highlight-title lg-highlight-function">adminCommand</span>( <!-- -->{ <span class="lg-highlight-attr">shardCollection</span>: <span class="lg-highlight-string">"records.people"</span>, <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-attr">zipcode</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>
  <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/command/refineCollectionShardKey/#mongodb-dbcommand-dbcmd.refineCollectionShardKey">
        <code class="leafygreen-ui-1l06pbn">
         refineCollectionShardKey
        </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.balancerCollectionStatus/#mongodb-method-sh.balancerCollectionStatus">
        <code class="leafygreen-ui-1l06pbn">
         sh.balancerCollectionStatus()
        </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.shardCollection/#mongodb-method-sh.shardCollection">
        <code class="leafygreen-ui-1l06pbn">
         sh.shardCollection()
        </code>
       </a>
      </p>
     </li>
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/sharding/">
        Sharding
       </a>
      </p>
     </li>
    </ul>
   </div>
  </div>
 </section>
</section>
