簡體   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