<section>
 <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
  Troubleshoot Shard Keys
  <a class="headerlink leafygreen-ui-1kepx47" href="#troubleshoot-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="troubleshoot-shard-keys">
   </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="#jumbo-chunks" target="_self">
     <span>
      Jumbo Chunks
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#uneven-load-distribution" target="_self">
     <span>
      Uneven Load Distribution
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#decreased-query-performance-over-time" target="_self">
     <span>
      Decreased Query Performance Over Time
     </span>
    </a>
   </li>
  </ul>
 </div>
 <p class="leafygreen-ui-1kp3ins">
  The ideal shard key allows MongoDB to distribute documents evenly
throughout the cluster while facilitating common query patterns. A
suboptimal shard key can lead to the following problems:
 </p>
 <ul class="leafygreen-ui-rioki0">
  <li class="leafygreen-ui-d7p7b6">
   <p class="leafygreen-ui-1kp3ins">
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sharding-troubleshooting-jumbo-chunks" target="_self">
     <span>
      Jumbo chunks
     </span>
    </a>
   </p>
  </li>
  <li class="leafygreen-ui-d7p7b6">
   <p class="leafygreen-ui-1kp3ins">
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sharding-troubleshooting-monotonicity" target="_self">
     <span>
      Uneven load distribution
     </span>
    </a>
   </p>
  </li>
  <li class="leafygreen-ui-d7p7b6">
   <p class="leafygreen-ui-1kp3ins">
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sharding-troubleshooting-scatter-gather" target="_self">
     <span>
      Decreased query performance over time
     </span>
    </a>
   </p>
  </li>
 </ul>
 <p class="leafygreen-ui-1kp3ins">
  In the following you can find out more about common problems with shard
keys and how to resolve them.
 </p>
 <span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-troubleshooting-jumbo-chunks">
 </span>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Jumbo Chunks
   <a class="headerlink leafygreen-ui-1kepx47" href="#jumbo-chunks" 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="jumbo-chunks">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   If you are seeing
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-jumbo-chunks">
    jumbo chunks
   </a>
   , either the
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-shard-key-cardinality">
    cardinality
   </a>
   of your shard key is
insufficient or the
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-shard-key-frequency">
    frequency
   </a>
   of the shard
key values is unevenly distributed.
  </p>
  <p class="leafygreen-ui-1kp3ins">
   To increase the cardinality of your shard key or change the distribution
of your shard key values, you can:
  </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-refine-a-shard-key/#std-label-shard-key-refine">
      refine your shard key
     </a>
     by adding a suffix
field or fields to the existing key to increase cardinality
    </p>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding">
      reshard your collection
     </a>
     using a
different shard key with higher cardinality
    </p>
   </li>
  </ul>
  <p class="leafygreen-ui-1kp3ins">
   To learn whether you should reshard your collection
or refine your shard key, see
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-change-a-shard-key/#std-label-change-a-shard-key">
    Change a Shard Key
    <!-- -->
    .
   </a>
  </p>
  <p class="leafygreen-ui-1kp3ins">
   To only change the distribution of your shard key values, you can also
consider using
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/hashed-sharding/">
    Hashed Sharding
   </a>
   to distribute your data more
evenly.
  </p>
  <p class="leafygreen-ui-1kp3ins">
   For advice on choosing a shard key see
   <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>
  <span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-troubleshooting-monotonicity">
  </span>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Uneven Load Distribution
   <a class="headerlink leafygreen-ui-1kepx47" href="#uneven-load-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="uneven-load-distribution">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   If your cluster is experiencing uneven load distribution, check if your
shard key increases
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-shard-key-monotonic">
    monotonically
   </a>
   . A shard
key that is a monotonically increasing field, leads to an uneven read
and write distribution.
  </p>
  <p class="leafygreen-ui-1kp3ins">
   Consider an
   <code class="leafygreen-ui-1l06pbn">
    orders
   </code>
   collection that is sharded on an
   <code class="leafygreen-ui-1l06pbn">
    order_id
   </code>
   field. The
   <code class="leafygreen-ui-1l06pbn">
    order_id
   </code>
   is an integer which increases by one with each
order.
  </p>
  <span class="leafygreen-ui-1qnjd6d" id="std-label-shard-hotness">
  </span>
  <ul class="leafygreen-ui-rioki0">
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     New documents are generally written to the same shard and chunk. The
shard and chunk that receive the writes are called
     <em>
      hot
     </em>
     shard and
     <em>
      hot
     </em>
     chunk. The
     <em>
      hot
     </em>
     shard changes over time. When chunks are split,
the hot chunk moves to a different shard to optimize data
distribution.
    </p>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     If users are more likely to interact with recent orders, which are all
on the same shard, the shard that contains recent orders will receive
most of the traffic.
    </p>
   </li>
  </ul>
  <p class="leafygreen-ui-1kp3ins">
   If you have a monotonically increasing shard key, consider
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding">
    resharding your collection
   </a>
   . For advice on
choosing a shard key see
   <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>
  <p class="leafygreen-ui-1kp3ins">
   If your data model requires sharding on a key that changes
monotonically, consider using
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/hashed-sharding/">
    Hashed Sharding
    <!-- -->
    .
   </a>
  </p>
  <span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-troubleshooting-scatter-gather">
  </span>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Decreased Query Performance Over Time
   <a class="headerlink leafygreen-ui-1kepx47" href="#decreased-query-performance-over-time" 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="decreased-query-performance-over-time">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   If you are noticing decreased query performance over time, it is
possible that your cluster is performing
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-sharding-query-patterns">
    scatter-gather queries
    <!-- -->
    .
   </a>
  </p>
  <p class="leafygreen-ui-1kp3ins">
   To evaluate if your cluster is performing scatter-gather queries, check
if your most common queries include the shard key.
  </p>
  <p class="leafygreen-ui-1kp3ins">
   If you include the shard key in your queries, check if your shard key is
hashed. With
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/hashed-sharding/">
    Hashed Sharding
   </a>
   , documents are not stored in
ascending or descending order of the shard key field value. Performing
range based queries on the shard key value on data that is not stored in
ascending or descending order results in less performant scatter-gather
queries. If range based queries on your shard key are a common access
pattern, consider
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding">
    resharding your collection
    <!-- -->
    .
   </a>
  </p>
  <p class="leafygreen-ui-1kp3ins">
   If you do not include the shard key in your most common queries, it is
possible that you could increase performance by
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding">
    resharding your
collection
   </a>
   . For advice on choosing a shard key
see
   <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>
 </section>
</section>
