<section>
 <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
  Aggregation with User Preference Data
  <a class="headerlink leafygreen-ui-1kepx47" href="#aggregation-with-user-preference-data" 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="aggregation-with-user-preference-data">
   </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="#data-model" target="_self">
     <span>
      Data Model
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#return-a-single-field" target="_self">
     <span>
      Return a Single Field
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#normalize-and-sort-documents" target="_self">
     <span>
      Normalize and Sort Documents
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#return-usernames-ordered-by-join-month" target="_self">
     <span>
      Return Usernames Ordered by Join Month
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#return-total-number-of-joins-per-month" target="_self">
     <span>
      Return Total Number of Joins per Month
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#return-the-five-most-common--likes-" target="_self">
     <span>
      Return the Five Most Common "Likes"
     </span>
    </a>
   </li>
  </ul>
 </div>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Data Model
   <a class="headerlink leafygreen-ui-1kepx47" href="#data-model" 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="data-model">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   Consider a sports club database with a
   <code class="leafygreen-ui-1l06pbn">
    members
   </code>
   collection that
tracks members' names, join dates, and sport preferences:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.members.insertMany( [\n   {\n      _id: \"jane\",\n      joined: ISODate(\"2011-03-02\"),\n      likes: [\"golf\", \"racquetball\"]\n   },\n   {\n      _id: \"joe\",\n      joined: ISODate(\"2012-07-02\"),\n      likes: [\"tennis\", \"golf\", \"swimming\"]\n   },\n   {\n      _id: \"ruth\",\n      joined: ISODate(\"2012-01-14\"),\n      likes: [\"golf\", \"racquetball\"]\n   },\n   {\n      _id: \"harold\",\n      joined: ISODate(\"2012-01-21\"),\n      likes: [\"handball\", \"golf\", \"racquetball\"]\n   },\n   {\n      _id: \"kate\",\n      joined: ISODate(\"2012-01-14\"),\n      likes: [\"swimming\", \"tennis\"]\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">members</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-attr">_id</span>: <span class="lg-highlight-string">"jane"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">joined</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2011-03-02"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">likes</span>: <!-- -->[<span class="lg-highlight-string">"golf"</span>, <span class="lg-highlight-string">"racquetball"</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-attr">_id</span>: <span class="lg-highlight-string">"joe"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">joined</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2012-07-02"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">likes</span>: <!-- -->[<span class="lg-highlight-string">"tennis"</span>, <span class="lg-highlight-string">"golf"</span>, <span class="lg-highlight-string">"swimming"</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-attr">_id</span>: <span class="lg-highlight-string">"ruth"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">joined</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2012-01-14"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">likes</span>: <!-- -->[<span class="lg-highlight-string">"golf"</span>, <span class="lg-highlight-string">"racquetball"</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-attr">_id</span>: <span class="lg-highlight-string">"harold"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">joined</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2012-01-21"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">likes</span>: <!-- -->[<span class="lg-highlight-string">"handball"</span>, <span class="lg-highlight-string">"golf"</span>, <span class="lg-highlight-string">"racquetball"</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-attr">_id</span>: <span class="lg-highlight-string">"kate"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">joined</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2012-01-14"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">likes</span>: <!-- -->[<span class="lg-highlight-string">"swimming"</span>, <span class="lg-highlight-string">"tennis"</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>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Return a Single Field
   <a class="headerlink leafygreen-ui-1kepx47" href="#return-a-single-field" 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="return-a-single-field">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   The following operation uses
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project">
    <code class="leafygreen-ui-1l06pbn">
     $project
    </code>
   </a>
   to return only the
   <code class="leafygreen-ui-1l06pbn">
    _id
   </code>
   field for all documents in the
   <code class="leafygreen-ui-1l06pbn">
    members
   </code>
   collection:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.members.aggregate(\n   [\n      { $project: { _id: 1 } }\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">members</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>: <!-- -->{ <span class="lg-highlight-attr">_id</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></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 operation returns the following documents:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n   { _id: 'jane' },\n   { _id: 'joe' },\n   { _id: 'ruth' },\n   { _id: 'harold' },\n   { _id: 'kate' }\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">_id</span>: <span class="lg-highlight-string">'jane'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'joe'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'ruth'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'harold'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'kate'</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre>
    </div>
   </div>
  </div>
  <p class="leafygreen-ui-1kp3ins">
   For basic query and projection operations, standard queries with the
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find">
    <code class="leafygreen-ui-1l06pbn">
     find()
    </code>
   </a>
   method have the best performance.
  </p>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Normalize and Sort Documents
   <a class="headerlink leafygreen-ui-1kepx47" href="#normalize-and-sort-documents" 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="normalize-and-sort-documents">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   The following operation returns member names in upper case and in
alphabetical order. You might do this to normalize member names for
processing.
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.members.aggregate(\n  [\n    { $project: { name: { $toUpper: \"$_id\" }, _id: 0 } },\n    { $sort: { name: 1 } }\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">members</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>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <!-- -->{ <span class="lg-highlight-attr">$toUpper</span>: <span class="lg-highlight-string">"$_id"</span> }<!-- -->, <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">$sort</span>: <!-- -->{ <span class="lg-highlight-attr">name</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></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">
   All documents from the
   <code class="leafygreen-ui-1l06pbn">
    members
   </code>
   collection pass through the
pipeline, which consists of the following operations:
  </p>
  <ul class="leafygreen-ui-rioki0">
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     The
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project">
      <code class="leafygreen-ui-1l06pbn">
       $project
      </code>
     </a>
     operator:
    </p>
    <ul class="leafygreen-ui-rioki0">
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       creates a new field called
       <code class="leafygreen-ui-1l06pbn">
        name
       </code>
       .
      </p>
     </li>
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       converts the value of the
       <code class="leafygreen-ui-1l06pbn">
        _id
       </code>
       to upper case, with the
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/toUpper/#mongodb-expression-exp.-toUpper">
        <code class="leafygreen-ui-1l06pbn">
         $toUpper
        </code>
       </a>
       operator. Then the
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project">
        <code class="leafygreen-ui-1l06pbn">
         $project
        </code>
       </a>
       creates a new field, named
       <code class="leafygreen-ui-1l06pbn">
        name
       </code>
       to hold this value.
      </p>
     </li>
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       suppresses the
       <code class="leafygreen-ui-1l06pbn">
        id
       </code>
       field.
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project">
        <code class="leafygreen-ui-1l06pbn">
         $project
        </code>
       </a>
       will pass
the
       <code class="leafygreen-ui-1l06pbn">
        _id
       </code>
       field by default, unless explicitly suppressed.
      </p>
     </li>
    </ul>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     The
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#mongodb-pipeline-pipe.-sort">
      <code class="leafygreen-ui-1l06pbn">
       $sort
      </code>
     </a>
     operator orders the results by the
     <code class="leafygreen-ui-1l06pbn">
      name
     </code>
     field.
    </p>
   </li>
  </ul>
  <p class="leafygreen-ui-1kp3ins">
   The operation returns the following result:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n   { name: 'HAROLD' },\n   { name: 'JANE' },\n   { name: 'JOE' },\n   { name: 'KATE' },\n   { name: 'RUTH' }\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">name</span>: <span class="lg-highlight-string">'HAROLD'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'JANE'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'JOE'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'KATE'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'RUTH'</span> }</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">
   Return Usernames Ordered by Join Month
   <a class="headerlink leafygreen-ui-1kepx47" href="#return-usernames-ordered-by-join-month" 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="return-usernames-ordered-by-join-month">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   The following aggregation operation returns member names sorted by the
month they joined. You might use this aggregation to help generate
membership renewal notices.
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.members.aggregate( [\n    {\n      $project: {\n         month_joined: { $month: \"$joined\" },\n         name: \"$_id\",\n         _id: 0\n       }\n    },\n    { $sort: { month_joined: 1 } }\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">members</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">month_joined</span>: <!-- -->{ <span class="lg-highlight-attr">$month</span>: <span class="lg-highlight-string">"$joined"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"$_id"</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">       }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <!-- -->{ <span class="lg-highlight-attr">$sort</span>: <!-- -->{ <span class="lg-highlight-attr">month_joined</span>: <span class="lg-highlight-number">1</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 pipeline passes all documents in the
   <code class="leafygreen-ui-1l06pbn">
    members
   </code>
   collection through
the following operations:
  </p>
  <ul class="leafygreen-ui-rioki0">
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     The
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project">
      <code class="leafygreen-ui-1l06pbn">
       $project
      </code>
     </a>
     operator:
    </p>
    <ul class="leafygreen-ui-rioki0">
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       Creates two new fields:
       <code class="leafygreen-ui-1l06pbn">
        month_joined
       </code>
       and
       <code class="leafygreen-ui-1l06pbn">
        name
       </code>
       .
      </p>
     </li>
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       Suppresses the
       <code class="leafygreen-ui-1l06pbn">
        id
       </code>
       from the results. The
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate">
        <code class="leafygreen-ui-1l06pbn">
         aggregate()
        </code>
       </a>
       method includes the
       <code class="leafygreen-ui-1l06pbn">
        _id
       </code>
       , unless
explicitly suppressed.
      </p>
     </li>
    </ul>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     The
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/month/#mongodb-expression-exp.-month">
      <code class="leafygreen-ui-1l06pbn">
       $month
      </code>
     </a>
     operator converts the values of the
     <code class="leafygreen-ui-1l06pbn">
      joined
     </code>
     field to integer representations of the month. Then the
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project">
      <code class="leafygreen-ui-1l06pbn">
       $project
      </code>
     </a>
     operator assigns those values to the
     <code class="leafygreen-ui-1l06pbn">
      month_joined
     </code>
     field.
    </p>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     The
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#mongodb-pipeline-pipe.-sort">
      <code class="leafygreen-ui-1l06pbn">
       $sort
      </code>
     </a>
     operator sorts the results by the
     <code class="leafygreen-ui-1l06pbn">
      month_joined
     </code>
     field.
    </p>
   </li>
  </ul>
  <p class="leafygreen-ui-1kp3ins">
   The operation returns the following result:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n   { month_joined: 1, name: 'ruth' },\n   { month_joined: 1, name: 'harold' },\n   { month_joined: 1, name: 'kate' },\n   { month_joined: 3, name: 'jane' },\n   { month_joined: 7, name: 'joe' }\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">month_joined</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'ruth'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">month_joined</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'harold'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">month_joined</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'kate'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">month_joined</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'jane'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">month_joined</span>: <span class="lg-highlight-number">7</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'joe'</span> }</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">
   Return Total Number of Joins per Month
   <a class="headerlink leafygreen-ui-1kepx47" href="#return-total-number-of-joins-per-month" 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="return-total-number-of-joins-per-month">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   The following operation shows how many people joined each month of the
year. You might use this aggregated data for recruiting and marketing
strategies.
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.members.aggregate( [\n   { $project: { month_joined: { $month: \"$joined\" } } } ,\n   { $group: { _id: { month_joined: \"$month_joined\" } , number: { $sum: 1 } } },\n   { $sort: { \"_id.month_joined\": 1 } }\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">members</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">month_joined</span>: <!-- -->{ <span class="lg-highlight-attr">$month</span>: <span class="lg-highlight-string">"$joined"</span> } } } <!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">$group</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <!-- -->{ <span class="lg-highlight-attr">month_joined</span>: <span class="lg-highlight-string">"$month_joined"</span> } <!-- -->, <span class="lg-highlight-attr">number</span>: <!-- -->{ <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-number">1</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">$sort</span>: <!-- -->{ <span class="lg-highlight-string">"_id.month_joined"</span>: <span class="lg-highlight-number">1</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 pipeline passes all documents in the
   <code class="leafygreen-ui-1l06pbn">
    members
   </code>
   collection through
the following operations:
  </p>
  <ul class="leafygreen-ui-rioki0">
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     The
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project">
      <code class="leafygreen-ui-1l06pbn">
       $project
      </code>
     </a>
     operator creates a new field called
     <code class="leafygreen-ui-1l06pbn">
      month_joined
     </code>
     .
    </p>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     The
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/month/#mongodb-expression-exp.-month">
      <code class="leafygreen-ui-1l06pbn">
       $month
      </code>
     </a>
     operator converts the values of the
     <code class="leafygreen-ui-1l06pbn">
      joined
     </code>
     field to integer representations of the month. Then the
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project">
      <code class="leafygreen-ui-1l06pbn">
       $project
      </code>
     </a>
     operator assigns the values to the
     <code class="leafygreen-ui-1l06pbn">
      month_joined
     </code>
     field.
    </p>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     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>
     operator collects all documents with a
given
     <code class="leafygreen-ui-1l06pbn">
      month_joined
     </code>
     value and counts how many documents there are
for that value. Specifically, for each unique value,
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group">
      <code class="leafygreen-ui-1l06pbn">
       $group
      </code>
     </a>
     creates a new "per-month" document with two
fields:
    </p>
    <ul class="leafygreen-ui-rioki0">
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       <code class="leafygreen-ui-1l06pbn">
        _id
       </code>
       , which contains a nested document with the
       <code class="leafygreen-ui-1l06pbn">
        month_joined
       </code>
       field and its value.
      </p>
     </li>
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       <code class="leafygreen-ui-1l06pbn">
        number
       </code>
       , which is a generated field. The
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sum/#mongodb-group-grp.-sum">
        <code class="leafygreen-ui-1l06pbn">
         $sum
        </code>
       </a>
       operator increments this field by 1 for every document containing
the given
       <code class="leafygreen-ui-1l06pbn">
        month_joined
       </code>
       value.
      </p>
     </li>
    </ul>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     The
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#mongodb-pipeline-pipe.-sort">
      <code class="leafygreen-ui-1l06pbn">
       $sort
      </code>
     </a>
     operator sorts the documents created by
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group">
      <code class="leafygreen-ui-1l06pbn">
       $group
      </code>
     </a>
     according to the contents of the
     <code class="leafygreen-ui-1l06pbn">
      month_joined
     </code>
     field.
    </p>
   </li>
  </ul>
  <p class="leafygreen-ui-1kp3ins">
   The aggregation operation returns the following documents:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n   { _id: { month_joined: 1 }, number: 3 },\n   { _id: { month_joined: 3 }, number: 1 },\n   { _id: { month_joined: 7 }, number: 1 }\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">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">_id</span>: <!-- -->{ <span class="lg-highlight-attr">month_joined</span>: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-attr">number</span>: <span class="lg-highlight-number">3</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">_id</span>: <!-- -->{ <span class="lg-highlight-attr">month_joined</span>: <span class="lg-highlight-number">3</span> }<!-- -->, <span class="lg-highlight-attr">number</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">_id</span>: <!-- -->{ <span class="lg-highlight-attr">month_joined</span>: <span class="lg-highlight-number">7</span> }<!-- -->, <span class="lg-highlight-attr">number</span>: <span class="lg-highlight-number">1</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre>
     <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
      <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
       <div class="leafygreen-ui-xhlipt">
        <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
         <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
         </path>
        </svg>
       </div>
      </button>
     </div>
    </div>
   </div>
  </div>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Return the Five Most Common "Likes"
   <a class="headerlink leafygreen-ui-1kepx47" href="#return-the-five-most-common--likes-" 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="return-the-five-most-common--likes-">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   The following aggregation collects the top five most "liked" activities
in the data set. This type of analysis could help inform planning and
future development.
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.members.aggregate(\n  [\n    { $unwind: \"$likes\" },\n    { $group: { _id: \"$likes\" , number: { $sum: 1 } } },\n    { $sort: { number: -1 } },\n    { $limit: 5 }\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">members</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">$unwind</span>: <span class="lg-highlight-string">"$likes"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <!-- -->{ <span class="lg-highlight-attr">$group</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$likes"</span> <!-- -->, <span class="lg-highlight-attr">number</span>: <!-- -->{ <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-number">1</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <!-- -->{ <span class="lg-highlight-attr">$sort</span>: <!-- -->{ <span class="lg-highlight-attr">number</span>: <!-- -->-<span class="lg-highlight-number">1</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    <!-- -->{ <span class="lg-highlight-attr">$limit</span>: <span class="lg-highlight-number">5</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 pipeline begins with all documents in the
   <code class="leafygreen-ui-1l06pbn">
    members
   </code>
   collection,
and passes these documents through the following operations:
  </p>
  <ul class="leafygreen-ui-rioki0">
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     The
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unwind/#mongodb-pipeline-pipe.-unwind">
      <code class="leafygreen-ui-1l06pbn">
       $unwind
      </code>
     </a>
     operator separates each value in the
     <code class="leafygreen-ui-1l06pbn">
      likes
     </code>
     array, and creates a new version of the source document
for every element in the array.
    </p>
    <div class="leafygreen-ui-vg7qwp" role="note">
     <h2 class="leafygreen-ui-2xicti">
      Example
     </h2>
     <div class="leafygreen-ui-9mycqc">
      <p class="leafygreen-ui-1kp3ins">
       Given the following document from the
       <code class="leafygreen-ui-1l06pbn">
        members
       </code>
       collection:
      </p>
      <script class="structured_data" type="application/ld+json">
       {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n  _id: \"jane\",\n  joined: ISODate(\"2011-03-02\"),\n  likes: [\"golf\", \"racquetball\"]\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">_id</span>: <span class="lg-highlight-string">"jane"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-attr">joined</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2011-03-02"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-attr">likes</span>: <!-- -->[<span class="lg-highlight-string">"golf"</span>, <span class="lg-highlight-string">"racquetball"</span>]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
        </div>
       </div>
      </div>
      <p class="leafygreen-ui-1kp3ins">
       The
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unwind/#mongodb-pipeline-pipe.-unwind">
        <code class="leafygreen-ui-1l06pbn">
         $unwind
        </code>
       </a>
       operator outputs the following
documents:
      </p>
      <script class="structured_data" type="application/ld+json">
       {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n  _id: \"jane\",\n  joined: ISODate(\"2011-03-02\"),\n  likes: \"golf\"\n}\n{\n  _id: \"jane\",\n  joined: ISODate(\"2011-03-02\"),\n  likes: \"racquetball\"\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">_id</span>: <span class="lg-highlight-string">"jane"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-attr">joined</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2011-03-02"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-attr">likes</span>: <span class="lg-highlight-string">"golf"</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-attr">_id</span>: <span class="lg-highlight-string">"jane"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-attr">joined</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2011-03-02"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-attr">likes</span>: <span class="lg-highlight-string">"racquetball"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
        </div>
       </div>
      </div>
     </div>
    </div>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     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>
     operator collects all documents with the same
value for the
     <code class="leafygreen-ui-1l06pbn">
      likes
     </code>
     field and counts each grouping. With this
information,
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group">
      <code class="leafygreen-ui-1l06pbn">
       $group
      </code>
     </a>
     creates a new document with two
fields:
    </p>
    <ul class="leafygreen-ui-rioki0">
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       <code class="leafygreen-ui-1l06pbn">
        _id
       </code>
       , which contains the
       <code class="leafygreen-ui-1l06pbn">
        likes
       </code>
       value.
      </p>
     </li>
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       <code class="leafygreen-ui-1l06pbn">
        number
       </code>
       , which is a generated field. The
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sum/#mongodb-group-grp.-sum">
        <code class="leafygreen-ui-1l06pbn">
         $sum
        </code>
       </a>
       operator increments this field by 1 for every document containing
the given
       <code class="leafygreen-ui-1l06pbn">
        likes
       </code>
       value.
      </p>
     </li>
    </ul>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     The
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#mongodb-pipeline-pipe.-sort">
      <code class="leafygreen-ui-1l06pbn">
       $sort
      </code>
     </a>
     operator sorts these documents by the
     <code class="leafygreen-ui-1l06pbn">
      number
     </code>
     field in reverse order.
    </p>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     The
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/limit/#mongodb-pipeline-pipe.-limit">
      <code class="leafygreen-ui-1l06pbn">
       $limit
      </code>
     </a>
     operator only includes the first 5 result
documents.
    </p>
   </li>
  </ul>
  <p class="leafygreen-ui-1kp3ins">
   The aggregation operation returns the following documents:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n   { _id: 'golf', number: 4 },\n   { _id: 'racquetball', number: 3 },\n   { _id: 'tennis', number: 2 },\n   { _id: 'swimming', number: 2 },\n   { _id: 'handball', number: 1 }\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">_id</span>: <span class="lg-highlight-string">'golf'</span>, <span class="lg-highlight-attr">number</span>: <span class="lg-highlight-number">4</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'racquetball'</span>, <span class="lg-highlight-attr">number</span>: <span class="lg-highlight-number">3</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'tennis'</span>, <span class="lg-highlight-attr">number</span>: <span class="lg-highlight-number">2</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'swimming'</span>, <span class="lg-highlight-attr">number</span>: <span class="lg-highlight-number">2</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">'handball'</span>, <span class="lg-highlight-attr">number</span>: <span class="lg-highlight-number">1</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre>
    </div>
   </div>
  </div>
 </section>
</section>
