title: MongoDB v5.0.5 reference existing field in updateMany()
body: <p>First time using MongoDB and I'm having an issue that I would appreciate some help with please.</p>
  <p>Let's say I have a collection called &quot;students&quot; with documents in the collection structured as followed:</p>
  <pre><code>{
  &quot;_id&quot;: ObjectId(&quot;12345&quot;),
  &quot;Name&quot;: &quot;Joe Bloggs&quot;,
  &quot;Class_Grade&quot;: &quot;b&quot;
  &quot;Homework_Grade&quot;: &quot;c&quot;,
  }
  </code></pre>
  <p>I want to create an embedded document called <code>&quot;Grades&quot;</code> that contains the class and homework grade fields and applies this to every document in the collection to end up with:</p>
  <pre><code>{
  &quot;_id&quot;: ObjectId(&quot;12345&quot;),
  &quot;Name&quot;: &quot;Joe Bloggs&quot;,
  &quot;Class_Grade&quot;: &quot;b&quot;
  &quot;Homework_Grade&quot;: &quot;c&quot;,
  &quot;Grades&quot;: {
      &quot;Class_Grade&quot;: &quot;b&quot;,
      &quot;Homework_Grade&quot;: &quot;c&quot;,
      }
  }
  </code></pre>
  <p>I have been trying to achieve this using updateMany() in MongoShell:</p>
  <pre><code>db.students.updateMany({}, {$set: {Grades: {&quot;Class_Grade&quot;: $Class_Grade, &quot;Homework_Grade&quot;: $Homework_grade&quot;}}})
  </code></pre>
  <p>However, in doing so, I receive Reference Error: <code>$Class_Grade</code> is not defined. I have tried amending the reference to <code>$students.Class_Grade</code> and receive the same error.</p>
  <p>Your advice would be greatly appreciated</p>