[英]Express api with mongoose PUT
I have endpoint:我有端点:
router.put('/:customerId', async (req, res) => {
try {
const updatedCustomer = await Customer.updateOne(
{ _id: req.params.customerId },
req.body,
{ new: true }
);
res.send(updatedCustomer);
} catch {
res.json({ message: err });
}
});
const CustomerSchema = mongoose.Schema({
name: String,
surname: String
})
and after put request with only name value in my object still exist name and surname.在我的 object 中提出只有名称值的请求后,仍然存在姓名和姓氏。 I thought that my surname value will be delete.
我以为我的姓氏值会被删除。 It works fine or not?
它工作正常吗?
In your schema definition do the following在您的架构定义中执行以下操作
const CustomerSchema = mongoose.Schema({
name: String,
surname: String
},{
strict:false
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.