简体   繁体   English

nodejs put方法更新数据

[英]nodejs put method to update data

I'm trying to create a put method in nodejs(express) so I can move to frontend and update my data but when I go on postman and try it I get an error in my terminal.我正在尝试在 nodejs(express) 中创建一个 put 方法,以便我可以移动到前端并更新我的数据,但是当我在 postman 上的 go 并尝试它时,我的终端出现错误。

My error: AssertionError [ERR_ASSERTION]: Missing where attribute in the options parameter我的错误: AssertionError [ERR_ASSERTION]: Missing where attribute in the options parameter

app.put('/zoom/:id', function(req, res) {
    return data.update({
        subject: req.body.subject,
        MEETINGID: req.body.MEETINGID,
        Password: req.body.Password
    }).then(function (data) {
        if (data) {
            res.send(data)
        } else {
            res.status(400).send('Error')
        }
    })
})

You are updating data table by using update function but to use update function you should use where parameter in the update function so that it can be analyzed that which data to be updated.您正在使用更新 function 更新数据表,但要使用更新 function 您应该在更新 function 中使用 where 参数,以便可以分析要更新的数据。 For example:-例如:-

app.put('/zoom/:id', function(req, res) {
return data.update({
    subject: req.body.subject,
    MEETINGID: req.body.MEETINGID,
    Password: req.body.Password
}, {
    where : {
       id: id /*like this*/  }}).then(function (data) {
    if (data) {
        res.send(data)
    } else {
        res.status(400).send('Error')
    }
})

}) })

Hope this helps.希望这可以帮助。 please let me know.请告诉我。

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

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