title: How to update my nested array of another nested array in object in mongodb
body: <p>My problem is somehow related to this problem <a href="https://stackoverflow.com/questions/4669178/how-to-update-multiple-array-elements-in-mongodb">LINK</a>. However this is my problem..</p>
  <pre><code>{
      &quot;_id&quot;: ObjectId(&quot;4d2d8deff4e6c1d71fc29a07&quot;),
      &quot;comments&quot;: [{
              &quot;name&quot;: &quot;Len&quot;,
              &quot;_id&quot;: ObjectId(&quot;6241108375ed952ceb0187e3&quot;),
              &quot;data&quot;: [{
                  &quot;name&quot;:&quot;Len&quot;,
                  &quot;confirmation_likes&quot;:&quot;false&quot;,
                  &quot;_id&quot;:ObjectId(&quot;6241102d75ed952ceb0187dd&quot;)
               },{
                  &quot;name&quot;:&quot;Lilipad&quot;,
                  &quot;confirmation_likes&quot;:&quot;false&quot;,
                  &quot;_id&quot;:ObjectId(&quot;6241102d75ed952ceb0187da&quot;)
               }]
          } {
              &quot;name&quot;: &quot;Lilipad&quot;,
              &quot;_id&quot;: ObjectId(&quot;6241108375ed952ceb0187e5&quot;),
              &quot;data&quot;: [{
                  &quot;name&quot;:&quot;Len&quot;,
                  &quot;confirmation_likes&quot;:&quot;false&quot;,
                  &quot;_id&quot;:ObjectId(&quot;6241102d75ed952ceb0187dd&quot;)
               },{
                  &quot;name&quot;:&quot;Lilipad&quot;,
                  &quot;confirmation_likes&quot;:&quot;false&quot;,
                  &quot;_id&quot;:ObjectId(&quot;6241102d75ed952ceb0187da&quot;)
               }]
          } {
              &quot;name&quot;: &quot;Leni Robredo&quot;,
              &quot;_id&quot;: ObjectId(&quot;6241108375ed952ceb0187e9&quot;),
              &quot;data&quot;: [{
                  &quot;name&quot;:&quot;Len&quot;,
                  &quot;confirmation_likes&quot;:&quot;false&quot;,
                  &quot;_id&quot;:ObjectId(&quot;6241102d75ed952ceb0187dd&quot;)
               },{
                  &quot;name&quot;:&quot;Lilipad&quot;,
                  &quot;confirmation_likes&quot;:&quot;false&quot;,
                  &quot;_id&quot;:ObjectId(&quot;6241102d75ed952ceb0187da&quot;)
               }]
          }
          ...
      ]
  }
  </code></pre>
  <p>Now, what I want to happen here is when you get the <code>_id</code> of the comments such as <code>ObjectId(&quot;6241108375ed952ceb0187e3&quot;)</code>,<code>ObjectId(&quot;6241108375ed952ceb0187e5&quot;)</code>,<code>ObjectId(&quot;6241108375ed952ceb0187e9&quot;)</code>. I want update a new set of data for each of them, but I am so confused how I am gonna do it with the operator. This is how my inputs gonna work and the output.</p>
  <pre><code>parent_id = ObjectId(&quot;4d2d8deff4e6c1d71fc29a07&quot;)
  sub_id = ObjectId(&quot;6241108375ed952ceb0187e5&quot;)
  new_data = [{
                  &quot;name&quot;:&quot;Len&quot;,
                  &quot;confirmation_likes&quot;:&quot;false&quot;,
                  &quot;_id&quot;:ObjectId(&quot;6241102d75ed952ceb0187dd&quot;)
               },{
                  &quot;name&quot;:&quot;Lilipad&quot;,
                  &quot;confirmation_likes&quot;:&quot;false&quot;,
                  &quot;_id&quot;:ObjectId(&quot;6241102d75ed952ceb0187da&quot;)
               },{
                  &quot;name&quot;:&quot;Len&quot;,
                  &quot;confirmation_likes&quot;:&quot;false&quot;,
                  &quot;_id&quot;:ObjectId(&quot;6241102d75ed952ceb012131&quot;)
               }]
  
  </code></pre>
  <p>Output</p>
  <pre><code>{
      &quot;_id&quot;: ObjectId(&quot;4d2d8deff4e6c1d71fc29a07&quot;),
      &quot;comments&quot;: [{
              &quot;name&quot;: &quot;Len&quot;,
              &quot;_id&quot;: ObjectId(&quot;6241108375ed952ceb0187e3&quot;),
              &quot;data&quot;: [{
                  &quot;name&quot;:&quot;Len&quot;,
                  &quot;confirmation_likes&quot;:&quot;false&quot;,
                  &quot;_id&quot;:ObjectId(&quot;6241102d75ed952ceb0187dd&quot;)
               },{
                  &quot;name&quot;:&quot;Lilipad&quot;,
                  &quot;confirmation_likes&quot;:&quot;false&quot;,
                  &quot;_id&quot;:ObjectId(&quot;6241102d75ed952ceb0187da&quot;)
               }]
          } {
              &quot;name&quot;: &quot;Lilipad&quot;,
              &quot;_id&quot;: ObjectId(&quot;6241108375ed952ceb0187e5&quot;),
              &quot;new_data&quot;: [{
                  &quot;name&quot;:&quot;Len&quot;,
                  &quot;confirmation_likes&quot;:&quot;false&quot;,
                  &quot;_id&quot;:ObjectId(&quot;6241102d75ed952ceb0187dd&quot;)
               },{
                  &quot;name&quot;:&quot;Lilipad&quot;,
                  &quot;confirmation_likes&quot;:&quot;false&quot;,
                  &quot;_id&quot;:ObjectId(&quot;6241102d75ed952ceb0187da&quot;)
               },{
                  &quot;name&quot;:&quot;Len&quot;,
                  &quot;confirmation_likes&quot;:&quot;false&quot;,
                  &quot;_id&quot;:ObjectId(&quot;6241102d75ed952ceb012131&quot;)
               }]
          } {
              &quot;name&quot;: &quot;Leni Robredo&quot;,
              &quot;_id&quot;: ObjectId(&quot;6241108375ed952ceb0187e9&quot;),
              &quot;data&quot;: [{
                  &quot;name&quot;:&quot;Len&quot;,
                  &quot;confirmation_likes&quot;:&quot;false&quot;,
                  &quot;_id&quot;:ObjectId(&quot;6241102d75ed952ceb0187dd&quot;)
               },{
                  &quot;name&quot;:&quot;Lilipad&quot;,
                  &quot;confirmation_likes&quot;:&quot;false&quot;,
                  &quot;_id&quot;:ObjectId(&quot;6241102d75ed952ceb0187da&quot;)
               }]
          }
          ...
      ]
  }
  </code></pre>
  <p>As you see I use sub_id to get the id of the item of an array that I want to update its data..because I can use the same name but not the id so that's why I used _id of array items of <code>comments</code>.</p>
  <p>Now what If I want to my pass new all data in all id of comment array.. I already prepare a loop for that let say something likes this.</p>
  <pre><code>list_comment_id = [ObjectId(&quot;6241108375ed952ceb0187e3&quot;),
  ObjectId(&quot;6241108375ed952ceb0187e5&quot;),ObjectId(&quot;6241108375ed952ceb0187e9&quot;)]
  
  parent_id = ObjectId(&quot;4d2d8deff4e6c1d71fc29a07&quot;)
  new_data = [{
                  &quot;name&quot;:&quot;Len&quot;,
                  &quot;confirmation_likes&quot;:&quot;false&quot;,
                  &quot;_id&quot;:ObjectId(&quot;6241102d75ed952ceb0187dd&quot;)
               },{
                  &quot;name&quot;:&quot;Lilipad&quot;,
                  &quot;confirmation_likes&quot;:&quot;false&quot;,
                  &quot;_id&quot;:ObjectId(&quot;6241102d75ed952ceb0187da&quot;)
               },{
                  &quot;name&quot;:&quot;Len&quot;,
                  &quot;confirmation_likes&quot;:&quot;false&quot;,
                  &quot;_id&quot;:ObjectId(&quot;6241102d75ed952ceb012131&quot;)
               }]
  </code></pre>
  <p>And so that i will pass up all the data that my <code>list_comment_id</code> wants..</p>
  <p>I already tried something like this in my code</p>
  <pre><code>router.route('/append/:id').put((req,res) =&gt; {
      const { _id, sub_id, data} = req.body
      const main_id = req.params.id
  
      // Sub_id for comments _id items
      COMMENT.updateOne(
          {
              _id:main_id,
              &quot;comments._id&quot; : sub_id
          },
          {
              $set:{
                  data:data
              }
          }
      ).then((comments) =&gt; res.json(&quot;Likes List People Updated&quot;) )
      .catch(err =&gt; console.log(err))
  
  })
  </code></pre>
  <p>Anyone can help me please thank you?? I'll be gladly thankful.</p>