<section>
 <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
  Dollar-Prefixed Field Names
  <a class="headerlink leafygreen-ui-1kepx47" href="#dollar-prefixed-field-names" 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="dollar-prefixed-field-names">
   </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="#insert-operations" target="_self">
     <span>
      Insert Operations
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#document-replacing-updates" target="_self">
     <span>
      Document Replacing Updates
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#document-modifying-updates" target="_self">
     <span>
      Document Modifying Updates
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#updates-using-aggregation-pipelines" target="_self">
     <span>
      Updates Using Aggregation Pipelines
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#general-restrictions" target="_self">
     <span>
      General Restrictions
     </span>
    </a>
   </li>
  </ul>
 </div>
 <p class="leafygreen-ui-1kp3ins">
  This section summarizes how different insert and update operations
handle dollar (
  <code class="leafygreen-ui-1l06pbn">
   $
  </code>
  ) prefixed field names.
 </p>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Insert Operations
   <a class="headerlink leafygreen-ui-1kepx47" href="#insert-operations" 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="insert-operations">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   Dollar (
   <code class="leafygreen-ui-1l06pbn">
    $
   </code>
   ) prefixed fields are permitted as top level and nested
field names for inserts.
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sales.insertOne( {\n   \"$price\": 50.00,\n   \"quantity\": 30\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">sales</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"$price"</span>: <span class="lg-highlight-number">50.00</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"quantity"</span>: <span class="lg-highlight-number">30</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">
   Dollar (
   <code class="leafygreen-ui-1l06pbn">
    $
   </code>
   ) prefixed fields are permitted on inserts using otherwise
reserved words. Operator names like
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/inc/#mongodb-update-up.-inc">
    <code class="leafygreen-ui-1l06pbn">
     $inc
    </code>
   </a>
   can be used as
field names as well as words like
   <code class="leafygreen-ui-1l06pbn">
    id
   </code>
   ,
   <code class="leafygreen-ui-1l06pbn">
    db
   </code>
   , and
   <code class="leafygreen-ui-1l06pbn">
    ref
   </code>
   .
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.books.insertOne( {\n   \"$id\": \"h1961-01\",\n   \"location\": {\n      \"$db\": \"novels\",\n      \"$ref\": \"2007042768\",\n      \"$inc\": true\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">books</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</span>( <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"$id"</span>: <span class="lg-highlight-string">"h1961-01"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"location"</span>: <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-string">"$db"</span>: <span class="lg-highlight-string">"novels"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-string">"$ref"</span>: <span class="lg-highlight-string">"2007042768"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-string">"$inc"</span>: <span class="lg-highlight-literal">true</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">
   An update which creates a new document during an
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-upsert">
    upsert
   </a>
   is
treated as an
   <code class="leafygreen-ui-1l06pbn">
    insert
   </code>
   rather than an
   <code class="leafygreen-ui-1l06pbn">
    update
   </code>
   for field name
validation.
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-upsert">
    Upserts
   </a>
   can accept dollar (
   <code class="leafygreen-ui-1l06pbn">
    $
   </code>
   ) prefixed
fields. However,
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-upsert">
    upserts
   </a>
   are a special case and
similar update operations may cause an error if the
   <code class="leafygreen-ui-1l06pbn">
    match
   </code>
   portion
of the update selects an existing document.
  </p>
  <p class="leafygreen-ui-1kp3ins">
   This code sample has
   <code class="leafygreen-ui-1l06pbn">
    upsert: true
   </code>
   so it will insert a new document
if the collection doesn't already contain a document that matches the
query term,
   <code class="leafygreen-ui-1l06pbn">
    { "date": "2021-07-07" }
   </code>
   . If this sample code matches
an existing document, the update will fail since
   <code class="leafygreen-ui-1l06pbn">
    $hotel
   </code>
   is dollar
(
   <code class="leafygreen-ui-1l06pbn">
    $
   </code>
   ) prefixed.
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.expenses.updateOne(\n   { \"date\": \"2021-07-07\" },\n   { $set: {\n      \"phone\": 25.17,\n      \"$hotel\": 320.10\n   } },\n   { upsert: true }\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">expenses</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-string">"date"</span>: <span class="lg-highlight-string">"2021-07-07"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-string">"phone"</span>: <span class="lg-highlight-number">25.17</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-string">"$hotel"</span>: <span class="lg-highlight-number">320.10</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">   } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">upsert</span>: <span class="lg-highlight-literal">true</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">
   Document Replacing Updates
   <a class="headerlink leafygreen-ui-1kepx47" href="#document-replacing-updates" 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="document-replacing-updates">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   Update operators either replace existing fields with new documents
or else modify those fields. In cases where the update performs a
replacement, dollar (
   <code class="leafygreen-ui-1l06pbn">
    $
   </code>
   ) prefixed fields are not permitted as top
level field names.
  </p>
  <p class="leafygreen-ui-1kp3ins">
   Consider a document like
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n   \"_id\": \"E123\",\n   \"address\": {\n      \"$number\": 123,\n      \"$street\": \"Elm Road\"\n   },\n   \"$rooms\": {\n      \"br\": 2,\n      \"bath\": 1\n   }\n}"}
  </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 none 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">   "_id": "E123",</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   "address": {</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      "$number": 123,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      "$street": "Elm Road"</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   },</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   "$rooms": {</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      "br": 2,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">      "bath": 1</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">
   You could use an update operator that replaces an existing document to
modify the
   <code class="leafygreen-ui-1l06pbn">
    address.$street
   </code>
   field but you could not update the
   <code class="leafygreen-ui-1l06pbn">
    $rooms
   </code>
   field that way.
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.housing.updateOne(\n   { \"_id\": \"E123\" },\n   { $set: { \"address.$street\": \"Elm Ave\" } }\n)"}
  </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 none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.housing.updateOne(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   { "_id": "E123" },</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   { $set: { "address.$street": "Elm Ave" } }</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">
   Use
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setField/#mongodb-expression-exp.-setField">
    <code class="leafygreen-ui-1l06pbn">
     $setField
    </code>
   </a>
   as part of an aggregation pipeline to
   <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-dotDollar-aggregate-update" target="_self">
    <span>
     update top level
    </span>
   </a>
   dollar (
   <code class="leafygreen-ui-1l06pbn">
    $
   </code>
   )
prefixed fields like
   <code class="leafygreen-ui-1l06pbn">
    $rooms
   </code>
   .
  </p>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Document Modifying Updates
   <a class="headerlink leafygreen-ui-1kepx47" href="#document-modifying-updates" 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="document-modifying-updates">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   When an update modifies, rather than replaces, existing document
fields, dollar (
   <code class="leafygreen-ui-1l06pbn">
    $
   </code>
   ) prefixed fields can be top level field names.
Subfields can be accessed directly, but you need a helper method to
access the top level fields.
  </p>
  <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">
    <p class="leafygreen-ui-1kp3ins">
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/getField/#mongodb-expression-exp.-getField">
      <code class="leafygreen-ui-1l06pbn">
       $getField
      </code>
     </a>
     ,
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setField/#mongodb-expression-exp.-setField">
      <code class="leafygreen-ui-1l06pbn">
       $setField
      </code>
     </a>
     ,
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/literal/#mongodb-expression-exp.-literal">
      <code class="leafygreen-ui-1l06pbn">
       $literal
      </code>
     </a>
     ,
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceWith/#mongodb-pipeline-pipe.-replaceWith">
      <code class="leafygreen-ui-1l06pbn">
       $replaceWith
      </code>
     </a>
    </p>
   </div>
  </div>
  <p class="leafygreen-ui-1kp3ins">
   Consider a collection with documents like this inventory record:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n   _id: ObjectId(\"610023ad7d58ecda39b8d161\"),\n   \"part\": \"AB305\",\n   \"$bin\": 200,\n   \"quantity\": 100,\n   \"pricing\": { sale: true, \"$discount\": 60 }\n}"}
  </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 none 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">   _id: ObjectId("610023ad7d58ecda39b8d161"),</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   "part": "AB305",</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   "$bin": 200,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   "quantity": 100,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   "pricing": { sale: true, "$discount": 60 }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
    </div>
   </div>
  </div>
  <p class="leafygreen-ui-1kp3ins">
   The
   <code class="leafygreen-ui-1l06pbn">
    pricing.$discount
   </code>
   subfield can be queried directly.
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.findAndModify( {\n    query: { \"part\": { $eq: \"AB305\" } },\n    update: { $inc: { \"pricing.$discount\": 10 } }\n} )"}
  </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 none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.inventory.findAndModify( {</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    query: { "part": { $eq: "AB305" } },</td></tr><tr class=""><td class="leafygreen-ui-7razhx">    update: { $inc: { "pricing.$discount": 10 } }</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">
   Use
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/getField/#mongodb-expression-exp.-getField">
    <code class="leafygreen-ui-1l06pbn">
     $getField
    </code>
   </a>
   and
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/literal/#mongodb-expression-exp.-literal">
    <code class="leafygreen-ui-1l06pbn">
     $literal
    </code>
   </a>
   to access the
value of the top level
   <code class="leafygreen-ui-1l06pbn">
    $bin
   </code>
   field.
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.findAndModify( {\n   query: { $expr: {\n      $eq: [ { $getField: { $literal: \"$bin\" } }, 200 ]\n   } },\n   update: { $inc: { \"quantity\": 10 } }\n} )"}
  </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 none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">db.inventory.findAndModify( {</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   query: { $expr: {</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">      $eq: [ { $getField: { $literal: "$bin" } }, 200 ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   } },</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   update: { $inc: { "quantity": 10 } }</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>
  <span class="leafygreen-ui-1qnjd6d" id="std-label-dotDollar-aggregate-update">
  </span>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Updates Using Aggregation Pipelines
   <a class="headerlink leafygreen-ui-1kepx47" href="#updates-using-aggregation-pipelines" 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="updates-using-aggregation-pipelines">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   Use
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setField/#mongodb-expression-exp.-setField">
    <code class="leafygreen-ui-1l06pbn">
     $setField
    </code>
   </a>
   ,
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/getField/#mongodb-expression-exp.-getField">
    <code class="leafygreen-ui-1l06pbn">
     $getField
    </code>
   </a>
   , and
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/literal/#mongodb-expression-exp.-literal">
    <code class="leafygreen-ui-1l06pbn">
     $literal
    </code>
   </a>
   in the
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceWith/#mongodb-pipeline-pipe.-replaceWith">
    <code class="leafygreen-ui-1l06pbn">
     $replaceWith
    </code>
   </a>
   stage to modify
dollar (
   <code class="leafygreen-ui-1l06pbn">
    $
   </code>
   ) prefixed fields in an aggregation
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-pipeline">
    pipeline
    <!-- -->
    .
   </a>
  </p>
  <p class="leafygreen-ui-1kp3ins">
   Consider a collection of school records like:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n   \"_id\": 100001,\n   \"$term\": \"fall\",\n   \"registered\": true,\n   \"grade\": 4\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-string">"_id"</span>: <span class="lg-highlight-number">100001</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"$term"</span>: <span class="lg-highlight-string">"fall"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"registered"</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"grade"</span>: <span class="lg-highlight-number">4</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
    </div>
   </div>
  </div>
  <p class="leafygreen-ui-1kp3ins">
   Create a new collection for the spring semester using a
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-pipeline">
    pipeline
   </a>
   to update the dollar (
   <code class="leafygreen-ui-1l06pbn">
    $
   </code>
   ) prefixed
   <code class="leafygreen-ui-1l06pbn">
    $term
   </code>
   field.
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.school.aggregate( [\n   { $match: { \"registered\": true } },\n   { $replaceWith: {\n      $setField: {\n         field: { $literal: \"$term\" },\n         input: \"$$ROOT\",\n         value: \"spring\"\n   } } },\n   { $out: \"spring2022\" }\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">school</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">$match</span>: <!-- -->{ <span class="lg-highlight-string">"registered"</span>: <span class="lg-highlight-literal">true</span> } }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">$replaceWith</span>: <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">      <span class="lg-highlight-attr">$setField</span>: <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">field</span>: <!-- -->{ <span class="lg-highlight-attr">$literal</span>: <span class="lg-highlight-string">"$term"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">input</span>: <span class="lg-highlight-string">"$$ROOT"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">         <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-string">"spring"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">   } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->{ <span class="lg-highlight-attr">$out</span>: <span class="lg-highlight-string">"spring2022"</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">
   General Restrictions
   <a class="headerlink leafygreen-ui-1kepx47" href="#general-restrictions" 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="general-restrictions">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   In addition to the storage validation rules above, there are some
general restrictions on using dollar (
   <code class="leafygreen-ui-1l06pbn">
    $
   </code>
   ) prefixed field names.
These fields cannot:
  </p>
  <ul class="leafygreen-ui-rioki0">
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     Be indexed
    </p>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     Be used as part of a shard key
    </p>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     Be validated using
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/jsonSchema/#mongodb-query-op.-jsonSchema">
      <code class="leafygreen-ui-1l06pbn">
       $jsonSchema
      </code>
     </a>
    </p>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     Be be modified with an escape sequence
    </p>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     Be used with
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/security/client-side-field-level-encryption-guide/" target="_self">
      <span>
       Field Level Encryption
      </span>
     </a>
    </p>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     Be used as a subfield in an
     <code class="leafygreen-ui-1l06pbn">
      _id
     </code>
     document
    </p>
   </li>
  </ul>
  <div class="leafygreen-ui-1sjx7ru" role="note">
   <h2 class="leafygreen-ui-29m78u">
    Warning
   </h2>
   <h3 class="leafygreen-ui-144d5kf">
    <strong>
     Possible Data Loss With Dollar Signs ($) and Periods (.)
    </strong>
   </h3>
   <div class="leafygreen-ui-9mycqc">
    <p class="leafygreen-ui-1kp3ins">
     There is a small chance of data loss when using dollar (
     <code class="leafygreen-ui-1l06pbn">
      $
     </code>
     ) prefixed
field names or field names that contain periods (
     <code class="leafygreen-ui-1l06pbn">
      .
     </code>
     ) if these
field names are used in conjunction with unacknowledged writes
(
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
      write concern
     </a>
     <code class="leafygreen-ui-1l06pbn">
      w=0
     </code>
     ) on servers
that are older than MongoDB 5.0.
    </p>
    <p class="leafygreen-ui-1kp3ins">
     When running
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/insert/#mongodb-dbcommand-dbcmd.insert">
      <code class="leafygreen-ui-1l06pbn">
       insert
      </code>
     </a>
     ,
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/update/#mongodb-dbcommand-dbcmd.update">
      <code class="leafygreen-ui-1l06pbn">
       update
      </code>
     </a>
     , and
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/findAndModify/#mongodb-dbcommand-dbcmd.findAndModify">
      <code class="leafygreen-ui-1l06pbn">
       findAndModify
      </code>
     </a>
     commands, drivers that are 5.0 compatible
remove restrictions on using documents with field names that are
dollar (
     <code class="leafygreen-ui-1l06pbn">
      $
     </code>
     ) prefixed or that contain periods (
     <code class="leafygreen-ui-1l06pbn">
      .
     </code>
     ). These field
names generated a client-side error in earlier driver versions.
    </p>
    <p class="leafygreen-ui-1kp3ins">
     The restrictions are removed regardless of the server version the
driver is connected to. If a 5.0 driver sends a document to an older
server, the document will be rejected without sending an error.
    </p>
   </div>
  </div>
  <div class="leafygreen-ui-1sjx7ru" role="note">
   <h2 class="leafygreen-ui-29m78u">
    Warning
   </h2>
   <h3 class="leafygreen-ui-144d5kf">
    <strong>
     Import and Export Concerns With Dollar Signs ($) and Periods (.)
    </strong>
   </h3>
   <div class="leafygreen-ui-9mycqc">
    <p class="leafygreen-ui-1kp3ins">
     Starting in MongoDB 5.0, document field names can be dollar (
     <code class="leafygreen-ui-1l06pbn">
      $
     </code>
     )
prefixed and can contain periods (
     <code class="leafygreen-ui-1l06pbn">
      .
     </code>
     ). However,
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoimport/#mongodb-binary-bin.mongoimport" target="_self">
      <span>
       <code class="leafygreen-ui-1l06pbn">
        mongoimport
       </code>
      </span>
     </a>
     and
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoexport/#mongodb-binary-bin.mongoexport" target="_self">
      <span>
       <code class="leafygreen-ui-1l06pbn">
        mongoexport
       </code>
      </span>
     </a>
     may not work
as expected in some situations with field names that make use of these
characters.
    </p>
    <p class="leafygreen-ui-1kp3ins">
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#std-label-extended-json-high-level-ref-v2">
      MongoDB Extended JSON v2
     </a>
     cannot differentiate between type wrappers and fields that happen to
have the same name as type wrappers. Do not use Extended JSON
formats in contexts where the corresponding BSON representations
might include dollar (
     <code class="leafygreen-ui-1l06pbn">
      $
     </code>
     ) prefixed keys. The
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-references/#std-label-dbref-explanation">
      DBRef
     </a>
     mechanism is an exception to this
general rule.
    </p>
    <p class="leafygreen-ui-1kp3ins">
     There are also restrictions on using
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoimport/#mongodb-binary-bin.mongoimport" target="_self">
      <span>
       <code class="leafygreen-ui-1l06pbn">
        mongoimport
       </code>
      </span>
     </a>
     and
     <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoexport/#mongodb-binary-bin.mongoexport" target="_self">
      <span>
       <code class="leafygreen-ui-1l06pbn">
        mongoexport
       </code>
      </span>
     </a>
     with periods (
     <code class="leafygreen-ui-1l06pbn">
      .
     </code>
     ) in field names. Since
CSV files use the period (
     <code class="leafygreen-ui-1l06pbn">
      .
     </code>
     ) to represent data hierarchies, a
period (
     <code class="leafygreen-ui-1l06pbn">
      .
     </code>
     ) in a field name will be misinterpreted as a level of
nesting.
    </p>
   </div>
  </div>
 </section>
</section>
