在node.js put方法中,我如何从多个处理程序中更新特定值?
- 在这里我从处理程序中更新数量(-1)的值。
- 我想从另一个处理程序中添加数量。
- 现在,如何通过在相同API和相同值的New Handler中从输入字段中添加新数量?
- Here I update the value of quantity (-1) from a handler .
- I want to add quantity from another handler.
- now how can add new quantity from a input field by new handler which is in the same Api and same value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我不建议根据客户端为您提供实际数量(请参阅
updatedProduct.quantity -1
),因为您永远无法信任它。 设置数量我会首先获取它,然后查看有一个具有该ID的产品,并从那里获取数量,甚至使用
$ inc ocer
https://www.mongodb.com/docs/manual/manual/reference/reference/operator/operator/update/ininc/ininc/不了解第2和3号问题。您能进一步解释吗?
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?