title: how do i update a nested array to add a unique ObjectId to each element?
body: <p>i have tried 2 methods and both did not work</p>
  <pre><code>db.exams.updateMany({},{$set: {&quot;exams.$[].questions.$[].id&quot; : new ObjectId()  }  })
  </code></pre>
  <p>and</p>
  <pre><code>db.exams.aggregate([
      {$unwind:&quot;$exams&quot;},
      {$unwind:&quot;$exams.questions&quot;},
      {$unwind:&quot;$exams.questions.question&quot;},
      {$set:{&quot;exams.questions.id&quot; : new ObjectId() }}
  ])
  </code></pre>
  <p>I keep getting the same ObjectId for all elements , but i want it to generate a new objectId for each one</p>