title: Mongoose update in node.js
body: <p>I would like to update the quantity of the product, but it always inserts a new product to the inputBuffer instead of updating. How can I do a real updating?</p>
  <pre><code>[
    {
      &quot;_id&quot;: &quot;61ae51f22e8fe709d477f19d&quot;,
      &quot;name&quot;: &quot;ALINE-1&quot;,
      &quot;steps&quot;: [
        {
          &quot;_id&quot;: &quot;61ae51f22e8fe709d477f19e&quot;,
          &quot;inputBuffer&quot;: [
            {
              &quot;prodQuantity&quot;: 5,
              &quot;_id&quot;: &quot;61ae52012e8fe709d477f1a0&quot;,
              &quot;prodName&quot;: &quot;cogs&quot;
            }
          ],
          &quot;outputBuffer&quot;: []
        }
      ],
      &quot;__v&quot;: 0
    }
  ]
  </code></pre>
  <p>and the code:</p>
  <pre><code>const updateProductInInputBuffer = ({ assemblyLineName, steps, prodName, prodQuantity }) =&gt; {
    return new Promise((resolve, reject) =&gt; {
      const filter = ({ name: assemblyLineName });
      AssemblyLine.findOneAndUpdate(filter, {
        $set: {
          [`steps.${steps - 1}.inputBuffer.$[p].prodQuantity`]: prodQuantity
        }
      }, {
        new: true,
        arrayFilters: [
          {
            'p.prodName': prodName
          }
        ]
      }).then((documents) =&gt; {
        resolve(documents);
      }).catch((err) =&gt; {
        logger.info('updating error');
        reject(err);
      });
    });
  };
  </code></pre>