node.js express mongoose 更新一条数据

柳镜
2023-12-01
// 修改购物车数据
router.post('/cartEdit', (req, res, next) => {
    let userId = req.cookies.userId;
    let productId = req.body.productId;
    let productNum = req.body.productNum;
    User.findOneAndUpdate({userId: userId, 'cartList.productId': productId}, {
        'cartList.$.productNum': productNum
    }, (error, document) => {
        if (error) {
            res.json({
                status: '1',
                message: error.message,
                result: 'err'
            })
        } else {
            res.json({
                status: '0',
                message: '',
                result: 'suc'
            })
        }
    })
});

 

 类似资料: