title: I want to update sub document in array
body: <p>I now use mongooses to pull and pull subdocuments to the array, and now I want to change the contents of the detail field of that subdocument with the _id of the subdocument.</p>
  
  <pre><code>{
      subDocument: [{
          _id: ObjectId('123'),
          detail: 'I want update this part'          
      }]
  }
  </code></pre>
  
  <p>I tried to use the $set method as shown below but it did not work as expected.</p>
  
  <pre><code>Model.findByIdAndUpdate(uid, { $Set: {subDocument: {_id: _id}}});
  </code></pre>
  
  <p>Looking at the for statement as shown below is likely to have a bad effect on performance. So I want to avoid this method.</p>
  
  <pre><code>const data = findById(uid);
  
  for(...) {
      if(data.subDocument[i]._id==_id) {
          data.subDocument[i].detail = detail
      }
  }
  </code></pre>
  
  <p>Can you tell me some mongodb queries that I can implement?</p>
  
  <p>And, Is it not better to use the 'for(;;)' statement shown above than to search using mongodb's query?</p>