繁体   English   中英

快递 api 与 mongoose PUT

[英]Express api with mongoose PUT

我有端点:

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
})

在我的 object 中提出只有名称值的请求后,仍然存在姓名和姓氏。 我以为我的姓氏值会被删除。 它工作正常吗?

在您的架构定义中执行以下操作

const CustomerSchema = mongoose.Schema({
    name: String,
    surname: String
},{
    strict:false
})

暂无
暂无

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

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