简体   繁体   English

在 Node.js PUT 方法中,我如何从多个处理程序更新特定值?

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

enter image description here在此处输入图像描述

  1. Here I update the value of quantity (-1) from a handler .在这里,我从处理程序更新数量 (-1) 的值。
  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?现在如何通过具有相同 Api 和相同值的新处理程序从输入字段中添加新数量?

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.首先,我不建议依赖客户给你实际数量(见updatedProduct.quantity - 1 )因为你永远不能相信它。 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我会先获取它并查看具有该 id 的产品并从那里获取数量,甚至使用$inc operator设置数量

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

I didn't understand questions number 2 and 3. Can you explain further?我不明白第 2 和第 3 个问题。你能进一步解释一下吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM