title: Find and update value in array of nested objects in mongo
body: <p>I have and object array as follows:</p>
  <pre><code>project: = {
      id: 111,
      title: &quot;Project TEST&quot;,
      tabs: [
        {
          tabId: 123,
          products: [
            {
              uniqId: 1,
              price: 180
              quantity:5
            },
            {
              uniqId: 2,
              price: 80
              quantity:2
            },
          ]
        },
        {
          tabId: 50,
          products: [
            {
              uniqId: 11,
              price: 180
              quantity:5
            },
            {
              uniqId: 12,// How I Identify this product inside the tab
              price: 80 // I want to update all this Product Object
              quantity:2 // I want to update all this Product Object
            },
          ]
        }
      ]
    }
  
  </code></pre>
  <p>Given a project ID = 111, a tabId = 50, and a product uniqId = 12, I want to update all the object Product. First I found the Project with findOne. Then I have to get the tab and the products. I have used arrayFilters of mongose docs. It doesn't update the project in database.</p>
  <p>How I can update this nested object array in the document?</p>
  <pre><code>async updateTabProduct(projectId,bodyProductToUpdate){
      try{
        const { Project: projectSchema } = this.getSchemas();
        const projec0t = await projectSchema.findOneAndUpdate(
        {
            &quot;_id&quot;: projectId,
            &quot;tabs&quot;: {
                &quot;$elemMatch&quot;: {
                    tabId, &quot;products.uniqId&quot;: body.uniqId
                }
            }
        },
        { &quot;$set&quot;: { 
            &quot;tabs.$[outer].products.$[inner].notes:&quot;: body.notes,
            &quot;tabs.$[outer].products.$[inner].nom:&quot;: &quot;asdfafd&quot;,
        } },
        { &quot;arrayFilters&quot;: [
            { &quot;outer.tabId&quot;: body.tabId },
            { &quot;inner.uniqId&quot;: body.uniqId }
        ] }, (err, result) =&gt; {
        if (err) {
            console.log('Error updating service: ' + err);
        } else {
        }
    }); 
    return projec0t;
   }
      catch(error) {
        throw error;
      }
    }
  </code></pre>