In Node.js PUT method how i can update a specific value from multiple handler?

205 Views Asked by At

enter image description here

  1. Here I update the value of quantity (-1) from a handler .
  2. I want to add quantity from another handler.
  3. now how can add new quantity from a input field by new handler which is in the same Api and same value?
1

There are 1 best solutions below

0
Ron Hillel On

First of all, I don't recommend depending on the client to give you the actual quantity (See updatedProduct.quantity - 1) cause you can never trust it. I would fetch it first and see there is a product with that id and get the quantity from there, or even set the quantity using the $inc operator

https://www.mongodb.com/docs/manual/reference/operator/update/inc/

I didn't understand questions number 2 and 3. Can you explain further?