title: Getting a 400 Error while trying to decrease counter on clicking a button and saving that Data on Database
body: <p>My Objective is to managing stock of Products. I have placed a button on product details page. On clicking that button, the stock of the products will be decreased by one and the updated stock will be stored in the Database.</p>
  <p>What I've done shows the decrement of the products on the console, but 400 error shows along with it and the data is not getting saved on the Database.</p>
  <p>The code I've written on the client-side-</p>
  <pre><code>        const newQty = parseInt(product.quantity) - 1;
          const quantity = newQty;
          console.log(quantity);
          const url = `http://localhost:5000/product/${productId}`;
          fetch(url, {
              method: 'PUT',
              headers: {
                  'content-Type': 'application/json'
              },
              body: JSON.stringify(quantity)
          })
              .then(response =&gt; response.json())
              .then(data =&gt; {
                  console.log(data);
                  setProduct(data)
              })
      }
  </code></pre>
  <p>Code on the Server-Side-</p>
  <pre><code>            const id = req.params.id;
              const newQty = req.body;
              console.log(newQty);
              const filter = { _id: ObjectId(id) };
              const options = { upsert: true };
              const updatedQty = {
                  $set: {
                      quantity: newQty.quantity
                  }
              };
              const result = await inventoryCollection.updateOne(filter, updatedQty, options);
              res.send(result);
          })
  </code></pre>
  <p>The Error I am having- <a href="https://i.stack.imgur.com/qsowa.png" rel="nofollow noreferrer">errorImage</a></p>
  <p>any help on this matter will be highly appreciated.</p>