<section>
 <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
  Variables in Aggregation Expressions
  <a class="headerlink leafygreen-ui-1kepx47" href="#variables-in-aggregation-expressions" 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="variables-in-aggregation-expressions">
   </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="#user-variables" target="_self">
     <span>
      User Variables
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#system-variables" target="_self">
     <span>
      System Variables
     </span>
    </a>
   </li>
  </ul>
 </div>
 <p class="leafygreen-ui-1kp3ins">
  <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
   Aggregation expressions
  </a>
  can use both
user-defined and system variables.
 </p>
 <p class="leafygreen-ui-1kp3ins">
  Variables can hold any
  <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-bson-types">
   BSON type data
  </a>
  .
To access the value of the variable, prefix the variable name with
double dollar signs (
  <code class="leafygreen-ui-1l06pbn">
   $$
  </code>
  ); i.e.
  <code class="leafygreen-ui-1l06pbn">
   "$$&lt;variable&gt;"
  </code>
  .
 </p>
 <p class="leafygreen-ui-1kp3ins">
  If the variable references an object, to access a specific field in the
object, use the dot notation; i.e.
  <code class="leafygreen-ui-1l06pbn">
   "$$&lt;variable&gt;.&lt;field&gt;"
  </code>
  .
 </p>
 <span class="leafygreen-ui-1qnjd6d" id="std-label-agg-user-variables">
 </span>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   User Variables
   <a class="headerlink leafygreen-ui-1kepx47" href="#user-variables" 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="user-variables">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   User variable names can contain the ascii characters
   <code class="leafygreen-ui-1l06pbn">
    [_a-zA-Z0-9]
   </code>
   and any non-ascii character.
  </p>
  <p class="leafygreen-ui-1kp3ins">
   User variable names must begin with a lowercase ascii letter
   <code class="leafygreen-ui-1l06pbn">
    [a-z]
   </code>
   or a non-ascii character.
  </p>
  <span class="leafygreen-ui-1qnjd6d" id="std-label-agg-system-variables">
  </span>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   System Variables
   <a class="headerlink leafygreen-ui-1kepx47" href="#system-variables" 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="system-variables">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   MongoDB offers the following system variables:
  </p>
  <div class="leafygreen-ui-skkc39" tabindex="0">
   <table class="leafygreen-ui-hr8lsv">
    <colgroup>
     <col style="width:15%"/>
     <col style="width:50%"/>
    </colgroup>
    <thead class="leafygreen-ui-a9ho40">
     <tr data-testid="leafygreen-ui-header-row">
      <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
       <div class="leafygreen-ui-ui0te9">
        <div>
         Variable
        </div>
       </div>
      </th>
      <th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
       <div class="leafygreen-ui-ui0te9">
        <div>
         Description
        </div>
       </div>
      </th>
     </tr>
    </thead>
    <tbody>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <dl class="variable">
          <dt>
           <code class="leafygreen-ui-1l06pbn">
            NOW
           </code>
           <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-variable-variable.NOW" 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-variable-variable.NOW">
            </div>
           </a>
          </dt>
          <dd>
          </dd>
         </dl>
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         A variable that returns the current datetime value.
         <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-variable-variable.NOW" target="_self">
          <span>
           <code class="leafygreen-ui-1l06pbn">
            NOW
           </code>
          </span>
         </a>
         returns the same value for all members of the
deployment and remains the same throughout all stages of the
aggregation pipeline.
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <dl class="variable">
          <dt>
           <code class="leafygreen-ui-1l06pbn">
            CLUSTER_TIME
           </code>
           <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-variable-variable.CLUSTER_TIME" 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-variable-variable.CLUSTER_TIME">
            </div>
           </a>
          </dt>
          <dd>
          </dd>
         </dl>
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <p class="leafygreen-ui-1kp3ins">
          A variable that returns the current timestamp value.
         </p>
         <p class="leafygreen-ui-1kp3ins">
          <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-variable-variable.CLUSTER_TIME" target="_self">
           <span>
            <code class="leafygreen-ui-1l06pbn">
             CLUSTER_TIME
            </code>
           </span>
          </a>
          is only available on replica sets and
sharded clusters.
         </p>
         <p class="leafygreen-ui-1kp3ins">
          <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-variable-variable.CLUSTER_TIME" target="_self">
           <span>
            <code class="leafygreen-ui-1l06pbn">
             CLUSTER_TIME
            </code>
           </span>
          </a>
          returns the same value for all members
of the deployment and remains the same throughout all stages of
the pipeline.
         </p>
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <dl class="variable">
          <dt>
           <code class="leafygreen-ui-1l06pbn">
            ROOT
           </code>
           <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-variable-variable.ROOT" 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-variable-variable.ROOT">
            </div>
           </a>
          </dt>
          <dd>
          </dd>
         </dl>
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         References the root document, i.e. the top-level document, currently
being processed in the aggregation pipeline stage.
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <dl class="variable">
          <dt>
           <code class="leafygreen-ui-1l06pbn">
            CURRENT
           </code>
           <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-variable-variable.CURRENT" 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-variable-variable.CURRENT">
            </div>
           </a>
          </dt>
          <dd>
          </dd>
         </dl>
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <p class="leafygreen-ui-1kp3ins">
          References the start of the field path being processed in the
aggregation pipeline stage. Unless documented otherwise, all
stages start with
          <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-variable-variable.CURRENT" target="_self">
           <span>
            <code class="leafygreen-ui-1l06pbn">
             CURRENT
            </code>
           </span>
          </a>
          the same as
          <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-variable-variable.ROOT" target="_self">
           <span>
            <code class="leafygreen-ui-1l06pbn">
             ROOT
            </code>
            .
           </span>
          </a>
         </p>
         <p class="leafygreen-ui-1kp3ins">
          <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-variable-variable.CURRENT" target="_self">
           <span>
            <code class="leafygreen-ui-1l06pbn">
             CURRENT
            </code>
           </span>
          </a>
          is modifiable. However, since
          <code class="leafygreen-ui-1l06pbn">
           $&lt;field&gt;
          </code>
          is equivalent to
          <code class="leafygreen-ui-1l06pbn">
           $$CURRENT.&lt;field&gt;
          </code>
          , rebinding
          <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-variable-variable.CURRENT" target="_self">
           <span>
            <code class="leafygreen-ui-1l06pbn">
             CURRENT
            </code>
           </span>
          </a>
          changes the meaning of
          <code class="leafygreen-ui-1l06pbn">
           $
          </code>
          accesses.
         </p>
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <dl class="variable">
          <dt>
           <code class="leafygreen-ui-1l06pbn">
            REMOVE
           </code>
           <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-variable-variable.REMOVE" 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-variable-variable.REMOVE">
            </div>
           </a>
          </dt>
          <dd>
          </dd>
         </dl>
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <p class="leafygreen-ui-1kp3ins">
          A variable which evaluates to the missing value. Allows for the
exclusion of fields in
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields">
           <code class="leafygreen-ui-1l06pbn">
            $addFields
           </code>
          </a>
          and
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project">
           <code class="leafygreen-ui-1l06pbn">
            $project
           </code>
          </a>
          stages.
         </p>
         <p class="leafygreen-ui-1kp3ins">
          For examples that use
          <code class="leafygreen-ui-1l06pbn">
           $$REMOVE
          </code>
          , see:
         </p>
         <ul class="leafygreen-ui-rioki0">
          <li class="leafygreen-ui-d7p7b6">
           <p class="leafygreen-ui-1kp3ins">
            <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#std-label-addFields-remove-example">
             Remove Fields
            </a>
           </p>
          </li>
          <li class="leafygreen-ui-d7p7b6">
           <p class="leafygreen-ui-1kp3ins">
            <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#std-label-remove-example">
             Conditionally Exclude Fields
            </a>
           </p>
          </li>
         </ul>
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <dl class="variable">
          <dt>
           <code class="leafygreen-ui-1l06pbn">
            DESCEND
           </code>
           <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-variable-variable.DESCEND" 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-variable-variable.DESCEND">
            </div>
           </a>
          </dt>
          <dd>
          </dd>
         </dl>
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         One of the allowed results of a
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/redact/#mongodb-pipeline-pipe.-redact">
          <code class="leafygreen-ui-1l06pbn">
           $redact
          </code>
         </a>
         expression.
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <dl class="variable">
          <dt>
           <code class="leafygreen-ui-1l06pbn">
            PRUNE
           </code>
           <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-variable-variable.PRUNE" 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-variable-variable.PRUNE">
            </div>
           </a>
          </dt>
          <dd>
          </dd>
         </dl>
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         One of the allowed results of a
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/redact/#mongodb-pipeline-pipe.-redact">
          <code class="leafygreen-ui-1l06pbn">
           $redact
          </code>
         </a>
         expression.
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <dl class="variable">
          <dt>
           <code class="leafygreen-ui-1l06pbn">
            KEEP
           </code>
           <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-variable-variable.KEEP" 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-variable-variable.KEEP">
            </div>
           </a>
          </dt>
          <dd>
          </dd>
         </dl>
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         One of the allowed results of a
         <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/redact/#mongodb-pipeline-pipe.-redact">
          <code class="leafygreen-ui-1l06pbn">
           $redact
          </code>
         </a>
         expression.
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <dl class="variable">
          <dt>
           <code class="leafygreen-ui-1l06pbn">
            SEARCH_META
           </code>
           <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-variable-variable.SEARCH_META" 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-variable-variable.SEARCH_META">
            </div>
           </a>
          </dt>
          <dd>
          </dd>
         </dl>
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <p class="leafygreen-ui-1kp3ins">
          A variable that stores the metadata results of an
          <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/" target="_self">
           <span>
            Atlas
Search
           </span>
          </a>
          query. In all supported aggregation
pipeline stages, a field set to the variable
          <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-variable-variable.SEARCH_META" target="_self">
           <span>
            <code class="leafygreen-ui-1l06pbn">
             $$SEARCH_META
            </code>
           </span>
          </a>
          returns the
          <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/reference/atlas-search/query-syntax/#metadata-result-types" target="_self">
           <span>
            metadata results
           </span>
          </a>
          for the query.
         </p>
         <p class="leafygreen-ui-1kp3ins">
          For an example of its usage, see Atlas Search
          <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/reference/atlas-search/facet/#search_meta-aggregation-variable" target="_self">
           <span>
            facet
           </span>
          </a>
          and
          <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/reference/atlas-search/counting/#search_meta-aggregation-variable" target="_self">
           <span>
            count
            <!-- -->
            .
           </span>
          </a>
         </p>
        </div>
       </div>
      </td>
     </tr>
     <tr class="leafygreen-ui-15dvrnp">
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <dl class="variable">
          <dt>
           <code class="leafygreen-ui-1l06pbn">
            USER_ROLES
           </code>
           <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-variable-variable.USER_ROLES" 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-variable-variable.USER_ROLES">
            </div>
           </a>
          </dt>
          <dd>
          </dd>
         </dl>
        </div>
       </div>
      </td>
      <td class="leafygreen-ui-1drjk7h">
       <div class="leafygreen-ui-1n4j8xf">
        <div>
         <p class="leafygreen-ui-1kp3ins">
          Returns the
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/#std-label-roles">
           roles
          </a>
          assigned to the current user.
         </p>
         <p class="leafygreen-ui-1kp3ins">
          For use cases that include
          <code class="leafygreen-ui-1l06pbn">
           USER_ROLES
          </code>
          , see the
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#std-label-find-user-roles-system-variable-example">
           find
          </a>
          ,
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setIntersection/#std-label-setIntersection-user-roles-system-variable-example">
           aggregation
          </a>
          ,
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/views/create-view/#std-label-create-view-user-roles-system-variable-example">
           view
          </a>
          ,
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#std-label-updateOne-example-user-roles-system-variable">
           updateOne
          </a>
          ,
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateMany/#std-label-updateMany-example-user-roles-system-variable">
           updateMany
          </a>
          , and
          <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findAndModify/#std-label-findAndModify-example-user-roles-system-variable">
           findAndModify
          </a>
          examples.
         </p>
         <div>
          <p>
           <em>
            New
            <!-- -->
            in version
            <!-- -->
            7.0
           </em>
           .
          </p>
         </div>
        </div>
       </div>
      </td>
     </tr>
    </tbody>
   </table>
  </div>
  <div class="leafygreen-ui-13vw3ie" role="note">
   <h2 class="leafygreen-ui-1fn4p2b">
    Tip
   </h2>
   <h3 class="leafygreen-ui-144d5kf">
    <strong>
     See also:
    </strong>
   </h3>
   <div class="leafygreen-ui-9mycqc">
    <ul class="leafygreen-ui-rioki0">
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/let/#mongodb-expression-exp.-let">
        <code class="leafygreen-ui-1l06pbn">
         $let
        </code>
       </a>
      </p>
     </li>
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/redact/#mongodb-pipeline-pipe.-redact">
        <code class="leafygreen-ui-1l06pbn">
         $redact
        </code>
       </a>
      </p>
     </li>
     <li class="leafygreen-ui-d7p7b6">
      <p class="leafygreen-ui-1kp3ins">
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/map/#mongodb-expression-exp.-map">
        <code class="leafygreen-ui-1l06pbn">
         $map
        </code>
       </a>
      </p>
     </li>
    </ul>
   </div>
  </div>
 </section>
</section>
