1、通过put请求修改产品
// 发送put请求 修改产品title
// 只要是对mongodb有操作的,都需要添加await
app.put('/product/:id',async function(req,res){
// 1、根据id找到需要修改的产品且赋值给product
const product = await Product.findById(req.params.id);
// 2、将客户端传递来的title赋值给当前找到的产品
product.title = req.body.title;
// 3、将修改后的product保存
await product.save();
// 4、发送出去
res.send(product);
})
2、在test.http中编写put请求
每点击一次Send Request,就会发送一次put请求,且会将id为xxx的产品的title改为产品55
image.png
3、修改过程流程:
image.png
image.png