<section>
 <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
  $median (aggregation)
  <a class="headerlink leafygreen-ui-1kepx47" href="#-median--aggregation-" 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="-median--aggregation-">
   </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="#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="#behavior" target="_self">
     <span>
      Behavior
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#examples" target="_self">
     <span>
      Examples
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#learn-more" target="_self">
     <span>
      Learn More
     </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="group">
   <dt>
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-group-grp.-median" 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-group-grp.-median">
     </div>
    </a>
   </dt>
   <dd>
    <div>
     <p>
      <em>
       New
       <!-- -->
       in version
       <!-- -->
       7.0
      </em>
      .
     </p>
    </div>
    <p class="leafygreen-ui-1kp3ins">
     Returns an approximation of the
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-median">
      median
     </a>
     , the 50th
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-percentile">
      percentile
     </a>
     , as a scalar value.
    </p>
    <p class="leafygreen-ui-1kp3ins">
     You can use
     <code class="leafygreen-ui-1l06pbn">
      $median
     </code>
     as an
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#std-label-accumulators-group">
      accumulator
     </a>
     in the
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group">
      <code class="leafygreen-ui-1l06pbn">
       $group
      </code>
     </a>
     stage or as
an
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
      aggegation expression
      <!-- -->
      .
     </a>
    </p>
   </dd>
  </dl>
 </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">
   The syntax for
   <code class="leafygreen-ui-1l06pbn">
    $median
   </code>
   is:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n   $median: {\n      input: &lt;number&gt;,\n      method: &lt;string&gt;\n   }\n}","programmingLanguage":"JavaScript"}
  </script>
  <div class="css-1lju8ps">
   <div class="leafygreen-ui-196mwvg">
    <div class="leafygreen-ui-1jheeh3">
     <pre class="leafygreen-ui-1453az5" 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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-attr">$median</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">input</span>: &lt;<!-- -->number<!-- -->&gt;<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">method</span>: &lt;<!-- -->string<!-- -->&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>
   </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">
   <code class="leafygreen-ui-1l06pbn">
    $median
   </code>
   takes the following fields:
  </p>
  <div class="leafygreen-ui-skkc39" tabindex="0">
   <table class="leafygreen-ui-hr8lsv">
    <colgroup>
     <col style="width:15%"/>
     <col style="width:17%"/>
     <col style="width:17%"/>
     <col style="width:51%"/>
    </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>
         Necessity
        </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">
          input
         </code>
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         Expression
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         Required
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <code class="leafygreen-ui-1l06pbn">
          $median
         </code>
         calculates the 50th percentile value of this data.
         <code class="leafygreen-ui-1l06pbn">
          input
         </code>
         must be a field name or an expression that evaluates to
a numeric type. If the expression cannot be converted to a
numeric type, the
         <code class="leafygreen-ui-1l06pbn">
          $median
         </code>
         calculation ignores it.
        </div>
       </div>
      </td>
     </tr>
     <tr class="">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <code class="leafygreen-ui-1l06pbn">
          method
         </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>
         Required
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         The method that
         <code class="leafygreen-ui-1l06pbn">
          mongod
         </code>
         uses to calculate the 50th percentile
value. The method must be
         <code class="leafygreen-ui-1l06pbn">
          'approximate'
         </code>
         .
        </div>
       </div>
      </td>
     </tr>
    </tbody>
   </table>
  </div>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Behavior
   <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
    <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
     <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
     </path>
     <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
     </path>
    </svg>
    <div class="css-1btu0w3 evvkmar0" id="behavior">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   You can use
   <code class="leafygreen-ui-1l06pbn">
    $median
   </code>
   in:
  </p>
  <ul class="leafygreen-ui-rioki0">
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group">
      <code class="leafygreen-ui-1l06pbn">
       $group
      </code>
     </a>
     stages as an accumulator
    </p>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields">
      <code class="leafygreen-ui-1l06pbn">
       $setWindowFields
      </code>
     </a>
     stages as an accumulator
    </p>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project">
      <code class="leafygreen-ui-1l06pbn">
       $project
      </code>
     </a>
     stages as an aggregation expression
    </p>
   </li>
  </ul>
  <p class="leafygreen-ui-1kp3ins">
   <code class="leafygreen-ui-1l06pbn">
    $median
   </code>
   has the following characteristics as an accumulator, it:
  </p>
  <ul class="leafygreen-ui-rioki0">
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     Calculates a single result for all the documents in the stage.
    </p>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     Uses the
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://arxiv.org/abs/1902.04023" rel="noopener noreferrer">
      <span>
       t-digest
      </span>
      <svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
       <path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
       </path>
       <path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
       </path>
      </svg>
     </a>
     algorithm to
calculate approximate, percentile based metrics.
    </p>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     Uses approximate methods to scale to large volumes of data.
    </p>
   </li>
  </ul>
  <p class="leafygreen-ui-1kp3ins">
   <code class="leafygreen-ui-1l06pbn">
    $median
   </code>
   has the following characteristics as an aggregation
expression, it:
  </p>
  <ul class="leafygreen-ui-rioki0">
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     Accepts an array as input
    </p>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     Calculates a separate result for each input document
    </p>
   </li>
  </ul>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Type of Operation
    <a class="headerlink leafygreen-ui-1kepx47" href="#type-of-operation" 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="type-of-operation">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    In a
    <code class="leafygreen-ui-1l06pbn">
     $group
    </code>
    stage,
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    is an accumulator and calculates
a value for all documents in the window.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    In a
    <code class="leafygreen-ui-1l06pbn">
     $project
    </code>
    stage,
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    is an aggregation expression and
calculates values for each document.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    In
    <code class="leafygreen-ui-1l06pbn">
     $setWindowFields
    </code>
    stages,
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    returns a result
for each document like an aggregation expression, but the results are
computed over groups of documents like an accumulator.
   </p>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Calculation Considerations
    <a class="headerlink leafygreen-ui-1kepx47" href="#calculation-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="calculation-considerations">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    In
    <code class="leafygreen-ui-1l06pbn">
     $group
    </code>
    stages,
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    always uses an approximate
calculation method.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    In
    <code class="leafygreen-ui-1l06pbn">
     $project
    </code>
    stages,
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    might use the discrete
calculation method even when the approximate method is specified.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    In
    <code class="leafygreen-ui-1l06pbn">
     $setWindowFields
    </code>
    stages, the workload determines the calculation
method that
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    uses.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    The computed percentiles
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    returns might vary, even on the
same datasets. This is because the algorithm calculates approximate
values.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    Duplicate samples can cause ambiguity. If there are a large number of
duplicates, the percentile values may not represent the actual sample
distribution. Consider a data set where all the samples are the same.
All of the values in the data set fall at or below any percentile. A
"50th percentile" value would actually represent either 0 or 100 percent
of the samples.
   </p>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Array Input
    <a class="headerlink leafygreen-ui-1kepx47" href="#array-input" 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="array-input">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    If you use
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    as an aggregation expression in a
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project">
     <code class="leafygreen-ui-1l06pbn">
      $project
     </code>
    </a>
    stage, you can use an array as input.
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    ignores non-numeric array values.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    The syntax is:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n   $median:\n      {\n         input: [ &lt;expression1,&gt;, ..., &lt;expressionn&gt; ],\n         method: &lt;string&gt;\n      }\n}","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-1lju8ps">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-tyg50d">
      <pre class="leafygreen-ui-1453az5" 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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-attr">$median</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">input</span>: <!-- -->[ &lt;<!-- -->expression1<!-- -->, &lt;<!-- -->expression2<!-- -->&gt;<!-- -->,<!-- --> <!-- -->...<!-- -->, &lt;<!-- -->expressionN<!-- -->&gt; <!-- -->]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">method</span>: &lt;<!-- -->string<!-- -->&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>
    </div>
   </div>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Window Functions
    <a class="headerlink leafygreen-ui-1kepx47" href="#window-functions" 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="window-functions">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    A window function lets you calculate results over a moving "window" of
neighboring documents. As each document passes though the pipeline, the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields">
     <code class="leafygreen-ui-1l06pbn">
      $setWindowFields
     </code>
    </a>
    stage:
   </p>
   <ul class="leafygreen-ui-rioki0">
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      Recomputes the set of documents in the current window
     </p>
    </li>
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      calculates a value for all documents in the set
     </p>
    </li>
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      returns a single value for that document
     </p>
    </li>
   </ul>
   <p class="leafygreen-ui-1kp3ins">
    You can use
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    in a
    <code class="leafygreen-ui-1l06pbn">
     $setWindowFields
    </code>
    stage to calculate
rolling statistics for
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-manual-timeseries-landing">
     time series
    </a>
    or
other related data.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    When you use
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    in a
    <code class="leafygreen-ui-1l06pbn">
     $setWindowField
    </code>
    stage, the
    <code class="leafygreen-ui-1l06pbn">
     input
    </code>
    value must be a field name. If you enter an array instead of a
field name, the operation fails.
   </p>
  </section>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Examples
   <a class="headerlink leafygreen-ui-1kepx47" href="#examples" title="Permalink to this heading">
    <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
     <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
     </path>
     <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
     </path>
    </svg>
    <div class="css-1btu0w3 evvkmar0" id="examples">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   The following examples use the
   <code class="leafygreen-ui-1l06pbn">
    testScores
   </code>
   collection. Create the
collection:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.testScores.insertMany( [\n   { studentId: \"2345\", test01: 62, test02: 81, test03: 80 },\n   { studentId: \"2356\", test01: 60, test02: 83, test03: 79 },\n   { studentId: \"2358\", test01: 67, test02: 82, test03: 78 },\n   { studentId: \"2367\", test01: 64, test02: 72, test03: 77 },\n   { studentId: \"2369\", test01: 60, test02: 53, test03: 72 }\n] )","programmingLanguage":"JavaScript"}
  </script>
  <div class="css-16lmvu9">
   <div class="leafygreen-ui-196mwvg">
    <div class="leafygreen-ui-1b1bvay">
     <pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">testScores</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">"2345"</span>, <span class="lg-highlight-attr">test01</span>: <span class="lg-highlight-number">62</span>, <span class="lg-highlight-attr">test02</span>: <span class="lg-highlight-number">81</span>, <span class="lg-highlight-attr">test03</span>: <span class="lg-highlight-number">80</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">"2356"</span>, <span class="lg-highlight-attr">test01</span>: <span class="lg-highlight-number">60</span>, <span class="lg-highlight-attr">test02</span>: <span class="lg-highlight-number">83</span>, <span class="lg-highlight-attr">test03</span>: <span class="lg-highlight-number">79</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">"2358"</span>, <span class="lg-highlight-attr">test01</span>: <span class="lg-highlight-number">67</span>, <span class="lg-highlight-attr">test02</span>: <span class="lg-highlight-number">82</span>, <span class="lg-highlight-attr">test03</span>: <span class="lg-highlight-number">78</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">"2367"</span>, <span class="lg-highlight-attr">test01</span>: <span class="lg-highlight-number">64</span>, <span class="lg-highlight-attr">test02</span>: <span class="lg-highlight-number">72</span>, <span class="lg-highlight-attr">test03</span>: <span class="lg-highlight-number">77</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">"2369"</span>, <span class="lg-highlight-attr">test01</span>: <span class="lg-highlight-number">60</span>, <span class="lg-highlight-attr">test02</span>: <span class="lg-highlight-number">53</span>, <span class="lg-highlight-attr">test03</span>: <span class="lg-highlight-number">72</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>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Use
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    as an Accumulator
    <a class="headerlink leafygreen-ui-1kepx47" href="#use-operatorname-as-an-accumulator" 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="use-operatorname-as-an-accumulator">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    Create an accumulator that calculates the median value:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.testScores.aggregate( [\n   {\n      $group: {\n         _id: null,\n         test01_median: {\n            $median: {\n               input: \"$test01\",\n               method: 'approximate'\n            }\n         }\n      }\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-property">testScores</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">$group</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-literal">null</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">test01_median</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">            <span class="lg-highlight-attr">$median</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">               <span class="lg-highlight-attr">input</span>: <span class="lg-highlight-string">"$test01"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">               <span class="lg-highlight-attr">method</span>: <span class="lg-highlight-string">'approximate'</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">            }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      }</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>
   <p class="leafygreen-ui-1kp3ins">
    Output:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: null, test01_median: 62 }","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-1lju8ps">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-1jheeh3">
      <pre class="leafygreen-ui-1agdxuk" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-literal">null</span>, <span class="lg-highlight-attr">test01_median</span>: <span class="lg-highlight-number">62</span> }</td></tr></tbody></table></code></pre>
     </div>
    </div>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    The
    <code class="leafygreen-ui-1l06pbn">
     _id
    </code>
    field value is
    <code class="leafygreen-ui-1l06pbn">
     null
    </code>
    so
    <code class="leafygreen-ui-1l06pbn">
     $group
    </code>
    selects all the
documents in the collection.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    The
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    accumulator takes its input from the
    <code class="leafygreen-ui-1l06pbn">
     test01
    </code>
    field.
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    calculates the median value for the field,
    <code class="leafygreen-ui-1l06pbn">
     62
    </code>
    in this example.
   </p>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Use
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    in a
    <code class="leafygreen-ui-1l06pbn">
     $project
    </code>
    Stage
    <a class="headerlink leafygreen-ui-1kepx47" href="#use-operatorname-in-a--project-stage" 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="use-operatorname-in-a--project-stage">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    In a
    <code class="leafygreen-ui-1l06pbn">
     $group
    </code>
    stage,
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    is an accumulator and calculates
a single value for all documents. In a
    <code class="leafygreen-ui-1l06pbn">
     $project
    </code>
    stage,
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    is an aggregation expression and calculates values for
each document.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    You can use a field name or an array as input in a
    <code class="leafygreen-ui-1l06pbn">
     $project
    </code>
    stage.
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.testScores.aggregate( [\n   {\n      $project: {\n         _id: 0,\n         studentId: 1,\n         testMedians: {\n            $median: {\n               input: [ \"$test01\", \"$test02\", \"$test03\" ],\n               method: 'approximate'\n            }\n         }\n      }\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-property">testScores</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">$project</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">testMedians</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">            <span class="lg-highlight-attr">$median</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">               <span class="lg-highlight-attr">input</span>: <!-- -->[ <span class="lg-highlight-string">"$test01"</span>, <span class="lg-highlight-string">"$test02"</span>, <span class="lg-highlight-string">"$test03"</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">               <span class="lg-highlight-attr">method</span>: <span class="lg-highlight-string">'approximate'</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">            }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      }</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>
   <p class="leafygreen-ui-1kp3ins">
    Output:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ studentId: '2345', testMedians: 80 },\n{ studentId: '2356', testMedians: 79 },\n{ studentId: '2358', testMedians: 78 },\n{ studentId: '2367', testMedians: 72 },\n{ studentId: '2369', testMedians: 60 }","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-1lju8ps">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-1jheeh3">
      <pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">'2345'</span>, <span class="lg-highlight-attr">testMedians</span>: <span class="lg-highlight-number">80</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">'2356'</span>, <span class="lg-highlight-attr">testMedians</span>: <span class="lg-highlight-number">79</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">'2358'</span>, <span class="lg-highlight-attr">testMedians</span>: <span class="lg-highlight-number">78</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">'2367'</span>, <span class="lg-highlight-attr">testMedians</span>: <span class="lg-highlight-number">72</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">'2369'</span>, <span class="lg-highlight-attr">testMedians</span>: <span class="lg-highlight-number">60</span> }</td></tr></tbody></table></code></pre>
     </div>
    </div>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    When
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    is an aggregation expression there is a result for
each
    <code class="leafygreen-ui-1l06pbn">
     studentId
    </code>
    .
   </p>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Use
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    in a
    <code class="leafygreen-ui-1l06pbn">
     $setWindowField
    </code>
    Stage
    <a class="headerlink leafygreen-ui-1kepx47" href="#use-operatorname-in-a--setwindowfield-stage" 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="use-operatorname-in-a--setwindowfield-stage">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    To base your percentile values on local data trends, use
    <code class="leafygreen-ui-1l06pbn">
     $median
    </code>
    in a
    <code class="leafygreen-ui-1l06pbn">
     $setWindowField
    </code>
    aggregation pipeline stage.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    This example creates a window to filter scores:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.testScores.aggregate( [\n   {\n      $setWindowFields: {\n         sortBy: { test01: 1 },\n         output: {\n            test01_median: {\n               $median: {\n                  input: \"$test01\",\n                  method: 'approximate'\n               },\n               window: {\n                  range: [ -3, 3 ]\n               }\n            }\n         }\n      }\n   },\n   {\n      $project: {\n         _id: 0,\n         studentId: 1,\n         test01_median: 1\n      }\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-property">testScores</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">$setWindowFields</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">sortBy</span>: <!-- -->{ <span class="lg-highlight-attr">test01</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">output</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">            <span class="lg-highlight-attr">test01_median</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">               <span class="lg-highlight-attr">$median</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                  <span class="lg-highlight-attr">input</span>: <span class="lg-highlight-string">"$test01"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                  <span class="lg-highlight-attr">method</span>: <span class="lg-highlight-string">'approximate'</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">               }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">               <span class="lg-highlight-attr">window</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                  <span class="lg-highlight-attr">range</span>: <!-- -->[ <!-- -->-<span class="lg-highlight-number">3</span>, <span class="lg-highlight-number">3</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">               }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">            }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">$project</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">test01_median</span>: <span class="lg-highlight-number">1</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">      }</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>
   <p class="leafygreen-ui-1kp3ins">
    Output:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ studentId: '2356', test01_median: 60 },\n{ studentId: '2369', test01_median: 60 },\n{ studentId: '2345', test01_median: 60 },\n{ studentId: '2367', test01_median: 64 },\n{ studentId: '2358', test01_median: 64 }","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-1lju8ps">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-1jheeh3">
      <pre class="leafygreen-ui-1453az5" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">'2356'</span>, <span class="lg-highlight-attr">test01_median</span>: <span class="lg-highlight-number">60</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">'2369'</span>, <span class="lg-highlight-attr">test01_median</span>: <span class="lg-highlight-number">60</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">'2345'</span>, <span class="lg-highlight-attr">test01_median</span>: <span class="lg-highlight-number">60</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">'2367'</span>, <span class="lg-highlight-attr">test01_median</span>: <span class="lg-highlight-number">64</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">'2358'</span>, <span class="lg-highlight-attr">test01_median</span>: <span class="lg-highlight-number">64</span> }</td></tr></tbody></table></code></pre>
     </div>
    </div>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    In this example, the median calculation for each document also
incorporates data from the three documents before and after it.
   </p>
  </section>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Learn More
   <a class="headerlink leafygreen-ui-1kepx47" href="#learn-more" 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="learn-more">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   The
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/percentile/#mongodb-group-grp.-percentile">
    <code class="leafygreen-ui-1l06pbn">
     $percentile
    </code>
   </a>
   operator is a more general
version of the
   <code class="leafygreen-ui-1l06pbn">
    $median
   </code>
   operator that allows you to set one or
more percentile values.
  </p>
  <p class="leafygreen-ui-1kp3ins">
   For more information on window functions, see:
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields">
    <code class="leafygreen-ui-1l06pbn">
     $setWindowFields
    </code>
    .
   </a>
  </p>
 </section>
</section>
