简体   繁体   中英

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.

My error: 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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