<section>
 <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
  $isNumber (aggregation)
  <a class="headerlink leafygreen-ui-1kepx47" href="#-isnumber--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="-isnumber--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="#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="expression">
   <dt>
    <code class="leafygreen-ui-1l06pbn">
     $isNumber
    </code>
    <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-isNumber" 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-expression-exp.-isNumber">
     </div>
    </a>
   </dt>
   <dd>
    <p class="leafygreen-ui-1kp3ins">
     <code class="leafygreen-ui-1l06pbn">
      $isNumber
     </code>
     checks if the specified
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
      expression
     </a>
     resolves to one of the
following numeric
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-BSON-types">
      BSON types
      <!-- -->
      :
     </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/reference/mongodb-extended-json/#mongodb-bsontype-Int32">
        <code class="leafygreen-ui-1l06pbn">
         Integer
        </code>
       </a>
      </p>
     </li>
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Decimal128">
        <code class="leafygreen-ui-1l06pbn">
         Decimal
        </code>
       </a>
      </p>
     </li>
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Double">
        <code class="leafygreen-ui-1l06pbn">
         Double
        </code>
       </a>
      </p>
     </li>
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Int64">
        <code class="leafygreen-ui-1l06pbn">
         Long
        </code>
       </a>
      </p>
     </li>
    </ul>
    <p class="leafygreen-ui-1kp3ins">
     <code class="leafygreen-ui-1l06pbn">
      $isNumber
     </code>
     returns:
    </p>
    <ul class="leafygreen-ui-rioki0">
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       <code class="leafygreen-ui-1l06pbn">
        true
       </code>
       if the expression resolves to a number.
      </p>
     </li>
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       <code class="leafygreen-ui-1l06pbn">
        false
       </code>
       if the expression resolves to any other
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-bson-types">
        BSON type
       </a>
       ,
       <code class="leafygreen-ui-1l06pbn">
        null
       </code>
       , or
a missing field.
      </p>
     </li>
    </ul>
    <p class="leafygreen-ui-1kp3ins">
     <code class="leafygreen-ui-1l06pbn">
      $isNumber
     </code>
     has the following
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-agg-quick-ref-operator-expressions">
      operator expression syntax
      <!-- -->
      :
     </a>
    </p>
    <script class="structured_data" type="application/ld+json">
     {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $isNumber: &lt;expression&gt; }","programmingLanguage":"JavaScript"}
    </script>
    <div class="css-16lmvu9">
     <div class="leafygreen-ui-196mwvg">
      <div class="leafygreen-ui-yzcs8i">
       <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$isNumber</span>: &lt;<!-- -->expression<!-- -->&gt; <!-- -->}</td></tr></tbody></table></code></pre>
       <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
        <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
         <div class="leafygreen-ui-xhlipt">
          <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
           <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
           </path>
          </svg>
         </div>
        </button>
       </div>
      </div>
     </div>
    </div>
    <p class="leafygreen-ui-1kp3ins">
     The argument can be any valid
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
      expression
      <!-- -->
      .
     </a>
    </p>
   </dd>
  </dl>
  <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/operator/aggregation/type/#mongodb-expression-exp.-type">
        <code class="leafygreen-ui-1l06pbn">
         $type (Aggregation)
        </code>
       </a>
       - returns the BSON type of the argument.
      </p>
     </li>
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/type/#mongodb-query-op.-type">
        <code class="leafygreen-ui-1l06pbn">
         $type (Query)
        </code>
       </a>
       - filters fields based on BSON type.
      </p>
     </li>
    </ul>
   </div>
  </div>
 </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>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Use $isNumber to Check if a Field is Numeric
    <a class="headerlink leafygreen-ui-1kepx47" href="#use--isnumber-to-check-if-a-field-is-numeric" 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--isnumber-to-check-if-a-field-is-numeric">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    Issue the following operation against the
    <code class="leafygreen-ui-1l06pbn">
     examples.sensors
    </code>
    collection to populate test data:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"examples\").sensors.insertMany([\n  { \"_id\" : 1, \"reading\" : NumberDecimal(26.0) },\n  { \"_id\" : 2, \"reading\" : NumberLong(25.0) },\n  { \"_id\" : 3, \"reading\" : NumberInt(24) },\n  { \"_id\" : 4, \"reading\" : 24.0 },\n  { \"_id\" : 5, \"reading\" : \"24\" },\n  { \"_id\" : 6, \"reading\" : [ NumberDecimal(26) ]}\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">getSiblingDB</span>(<span class="lg-highlight-string">"examples"</span>).<span class="lg-highlight-property">sensors</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-number">26.0</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">25.0</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberInt</span>(<span class="lg-highlight-number">24</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <span class="lg-highlight-number">24.0</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <span class="lg-highlight-string">"24"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">6</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-number">26</span>) ]}</td></tr><tr class=""><td class="leafygreen-ui-7razhx">])</td></tr></tbody></table></code></pre>
      <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
       <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
        <div class="leafygreen-ui-xhlipt">
         <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
          <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
          </path>
         </svg>
        </div>
       </button>
      </div>
     </div>
    </div>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    The following aggregation uses the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields">
     <code class="leafygreen-ui-1l06pbn">
      $addFields
     </code>
    </a>
    aggregation
stage to add the following fields to each document:
   </p>
   <ul class="leafygreen-ui-rioki0">
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      <code class="leafygreen-ui-1l06pbn">
       isNumber
      </code>
      -  Indicates whether the value of
      <code class="leafygreen-ui-1l06pbn">
       reading
      </code>
      is an
integer, decimal, double, or long.
     </p>
    </li>
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      <code class="leafygreen-ui-1l06pbn">
       type
      </code>
      - Indicates the BSON type of
      <code class="leafygreen-ui-1l06pbn">
       reading
      </code>
      .
     </p>
    </li>
   </ul>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sensors.aggregate([{\n  $addFields : {\n    \"isNumber\" : { $isNumber : \"$reading\" },\n    \"hasType\" : {$type : \"$reading\"}\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">sensors</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(<!-- -->[<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->$addFields<!-- --> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"isNumber"</span> <!-- -->: <!-- -->{ <!-- -->$isNumber<!-- --> <!-- -->: <span class="lg-highlight-string">"$reading"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"hasType"</span> <!-- -->: <!-- -->{<!-- -->$type<!-- --> <!-- -->: <span class="lg-highlight-string">"$reading"</span>}</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">
    The aggregation operation returns the following results:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"reading\" : NumberDecimal(\"26.0000000000000\"), \"isNum \" : true, \"type\" : \"decimal\" }\n{ \"_id\" : 2, \"reading\" : NumberLong(25), \"isNum \" : true, \"type\" : \"long\" }\n{ \"_id\" : 3, \"reading\" : 24, \"isNum \" : true, \"type\" : \"int\" }\n{ \"_id\" : 4, \"reading\" : 24, \"isNum \" : true, \"type\" : \"double\" }\n{ \"_id\" : 5, \"reading\" : \"24\", \"isNum \" : false, \"type\" : \"string\" }\n{ \"_id\" : 6, \"reading\" : [ NumberDecimal(\"26.0000000000000\") ], \"isNum \" : false, \"type\" : \"array\" }","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">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-string">"26.0000000000000"</span>)<!-- -->, <span class="lg-highlight-string">"isNum "</span> <!-- -->: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"decimal"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">25</span>)<!-- -->, <span class="lg-highlight-string">"isNum "</span> <!-- -->: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"long"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <span class="lg-highlight-number">24</span>, <span class="lg-highlight-string">"isNum "</span> <!-- -->: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"int"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <span class="lg-highlight-number">24</span>, <span class="lg-highlight-string">"isNum "</span> <!-- -->: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"double"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <span class="lg-highlight-string">"24"</span>, <span class="lg-highlight-string">"isNum "</span> <!-- -->: <span class="lg-highlight-literal">false</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"string"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">6</span>, <span class="lg-highlight-string">"reading"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-title lg-highlight-class">NumberDecimal</span>(<span class="lg-highlight-string">"26.0000000000000"</span>) ]<!-- -->, <span class="lg-highlight-string">"isNum "</span> <!-- -->: <span class="lg-highlight-literal">false</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"array"</span> }</td></tr></tbody></table></code></pre>
     </div>
    </div>
   </div>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Conditionally Modify Fields using $isNumber
    <a class="headerlink leafygreen-ui-1kepx47" href="#conditionally-modify-fields-using--isnumber" 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="conditionally-modify-fields-using--isnumber">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    The
    <code class="leafygreen-ui-1l06pbn">
     grades
    </code>
    collection contains data on student grades. The
    <code class="leafygreen-ui-1l06pbn">
     grade
    </code>
    field may either store a string letter grade
    <em>
     or
    </em>
    a numeric point value.
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"examples\").grades.insertMany([\n  {\n    \"student_id\" : 457864153,\n    \"class_id\" : \"01\",\n    \"class_desc\" : \"Algebra\",\n    \"grade\" : \"A\"\n  },\n  {\n    \"student_id\" : 457864153,\n    \"class_id\" : \"02\",\n    \"class_desc\" : \"Chemistry\",\n    \"grade\" : 3.0\n  },\n  {\n    \"student_id\" : 978451637,\n    \"class_id\" : \"03\",\n    \"class_desc\" : \"Physics\",\n    \"grade\" : \"C\"\n  },\n  {\n    \"student_id\" : 978451637,\n    \"class_id\" : \"04\",\n    \"class_desc\" : \"English\",\n    \"grade\" : 4.0\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">getSiblingDB</span>(<span class="lg-highlight-string">"examples"</span>).<span class="lg-highlight-property">grades</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"student_id"</span> <!-- -->: <span class="lg-highlight-number">457864153</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"class_id"</span> <!-- -->: <span class="lg-highlight-string">"01"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"class_desc"</span> <!-- -->: <span class="lg-highlight-string">"Algebra"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-string">"A"</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">    <span class="lg-highlight-string">"student_id"</span> <!-- -->: <span class="lg-highlight-number">457864153</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"class_id"</span> <!-- -->: <span class="lg-highlight-string">"02"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"class_desc"</span> <!-- -->: <span class="lg-highlight-string">"Chemistry"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">3.0</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">    <span class="lg-highlight-string">"student_id"</span> <!-- -->: <span class="lg-highlight-number">978451637</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"class_id"</span> <!-- -->: <span class="lg-highlight-string">"03"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"class_desc"</span> <!-- -->: <span class="lg-highlight-string">"Physics"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-string">"C"</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">    <span class="lg-highlight-string">"student_id"</span> <!-- -->: <span class="lg-highlight-number">978451637</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"class_id"</span> <!-- -->: <span class="lg-highlight-string">"04"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"class_desc"</span> <!-- -->: <span class="lg-highlight-string">"English"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">4.0</span></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">
    The following aggregation uses the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields">
     <code class="leafygreen-ui-1l06pbn">
      $addFields
     </code>
    </a>
    stage to add a
    <code class="leafygreen-ui-1l06pbn">
     points
    </code>
    field containing the numeric grade value for that course. The
stage uses the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/cond/#mongodb-expression-exp.-cond">
     <code class="leafygreen-ui-1l06pbn">
      $cond
     </code>
    </a>
    operator to set the value of
    <code class="leafygreen-ui-1l06pbn">
     points
    </code>
    based on the output of
    <code class="leafygreen-ui-1l06pbn">
     $isNumber
    </code>
    :
   </p>
   <ul class="leafygreen-ui-rioki0">
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      If
      <code class="leafygreen-ui-1l06pbn">
       true
      </code>
      ,
      <code class="leafygreen-ui-1l06pbn">
       grades
      </code>
      already contains the numeric point value.
Set
      <code class="leafygreen-ui-1l06pbn">
       points
      </code>
      equal to
      <code class="leafygreen-ui-1l06pbn">
       grades
      </code>
      .
     </p>
    </li>
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      If
      <code class="leafygreen-ui-1l06pbn">
       false
      </code>
      ,
      <code class="leafygreen-ui-1l06pbn">
       grades
      </code>
      contains a string letter value. Use
      <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/switch/#mongodb-expression-exp.-switch">
       <code class="leafygreen-ui-1l06pbn">
        $switch
       </code>
      </a>
      to convert the letter grade to its equivalent
point value and assign to
      <code class="leafygreen-ui-1l06pbn">
       points
      </code>
      .
     </p>
    </li>
   </ul>
   <p class="leafygreen-ui-1kp3ins">
    The aggregation pipeline then uses 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 to
group on the
    <code class="leafygreen-ui-1l06pbn">
     student_id
    </code>
    and calculate the student's
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/avg/#mongodb-group-grp.-avg">
     <code class="leafygreen-ui-1l06pbn">
      average
     </code>
    </a>
    GPA.
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":" db.getSiblingDB(\"examples\").grades.aggregate([\n   {\n     $addFields: {\n       \"points\" : {\n         $cond : {\n           if : { $isNumber : \"$grade\" },\n           then: \"$grade\" ,\n           else: {\n             $switch : {\n               branches: [\n                 { case: {$eq : [\"$grade\" , \"A\"]}, then : 4.0 },\n                 { case: {$eq : [\"$grade\" , \"B\"]}, then : 3.0 },\n                 { case: {$eq : [\"$grade\" , \"C\"]}, then : 2.0 },\n                 { case: {$eq : [\"$grade\" , \"D\"]}, then : 1.0 },\n                 { case: {$eq : [\"$grade\" , \"F\"]}, then : 0.0 }\n               ]\n             }\n           }\n         }\n       }\n     }\n   },\n   {\n     $group : {\n       _id : \"$student_id\",\n       GPA : {\n         $avg : \"$points\"\n       }\n     }\n   }\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-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"examples"</span>).<span class="lg-highlight-property">grades</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">$addFields</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">       <span class="lg-highlight-string">"points"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <!-- -->$cond<!-- --> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">           <span class="lg-highlight-keyword">if</span> <!-- -->: <!-- -->{ <!-- -->$isNumber<!-- --> <!-- -->: <span class="lg-highlight-string">"$grade"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">           <span class="lg-highlight-attr">then</span>: <span class="lg-highlight-string">"$grade"</span> <!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">           <span class="lg-highlight-attr">else</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">             <!-- -->$switch<!-- --> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">               <span class="lg-highlight-attr">branches</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                 <!-- -->{ <span class="lg-highlight-attr">case</span>: <!-- -->{<!-- -->$eq<!-- --> <!-- -->: <!-- -->[<span class="lg-highlight-string">"$grade"</span> <!-- -->, <span class="lg-highlight-string">"A"</span>]}<!-- -->, <!-- -->then <!-- -->: <span class="lg-highlight-number">4.0</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                 <!-- -->{ <span class="lg-highlight-attr">case</span>: <!-- -->{<!-- -->$eq<!-- --> <!-- -->: <!-- -->[<span class="lg-highlight-string">"$grade"</span> <!-- -->, <span class="lg-highlight-string">"B"</span>]}<!-- -->, <!-- -->then <!-- -->: <span class="lg-highlight-number">3.0</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                 <!-- -->{ <span class="lg-highlight-attr">case</span>: <!-- -->{<!-- -->$eq<!-- --> <!-- -->: <!-- -->[<span class="lg-highlight-string">"$grade"</span> <!-- -->, <span class="lg-highlight-string">"C"</span>]}<!-- -->, <!-- -->then <!-- -->: <span class="lg-highlight-number">2.0</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                 <!-- -->{ <span class="lg-highlight-attr">case</span>: <!-- -->{<!-- -->$eq<!-- --> <!-- -->: <!-- -->[<span class="lg-highlight-string">"$grade"</span> <!-- -->, <span class="lg-highlight-string">"D"</span>]}<!-- -->, <!-- -->then <!-- -->: <span class="lg-highlight-number">1.0</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">                 <!-- -->{ <span class="lg-highlight-attr">case</span>: <!-- -->{<!-- -->$eq<!-- --> <!-- -->: <!-- -->[<span class="lg-highlight-string">"$grade"</span> <!-- -->, <span class="lg-highlight-string">"F"</span>]}<!-- -->, <!-- -->then <!-- -->: <span class="lg-highlight-number">0.0</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">   }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">     <!-- -->$group<!-- --> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">       <!-- -->_id <!-- -->: <span class="lg-highlight-string">"$student_id"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">       <span class="lg-highlight-variable lg-highlight-constant">GPA</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <!-- -->$avg<!-- --> <!-- -->: <span class="lg-highlight-string">"$points"</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></tbody></table></code></pre>
      <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
       <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
        <div class="leafygreen-ui-xhlipt">
         <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
          <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
          </path>
         </svg>
        </div>
       </button>
      </div>
     </div>
    </div>
   </div>
   <p class="leafygreen-ui-1kp3ins">
    The aggregation pipeline outputs one document per unique
    <code class="leafygreen-ui-1l06pbn">
     student_id
    </code>
    with that student's
    <code class="leafygreen-ui-1l06pbn">
     GPA
    </code>
    grade point average:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 457864153, \"GPA\" : 3.5 }\n{ \"_id\" : 978451637, \"GPA\" : 3 }","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-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">457864153</span>, <span class="lg-highlight-string">"GPA"</span> <!-- -->: <span class="lg-highlight-number">3.5</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">978451637</span>, <span class="lg-highlight-string">"GPA"</span> <!-- -->: <span class="lg-highlight-number">3</span> }</td></tr></tbody></table></code></pre>
     </div>
    </div>
   </div>
  </section>
 </section>
</section>
