首页 > 解决方案 > 我只想使用 expressjs 更新 cassandra 中的单个记录

问题描述

当我使用插入查询进行更新时,它可以正常工作,但是当我使用更新进行更新时,它会产生错误 404。我的代码如下:

router.post('/updateone', function (req, res, next) {

var id = req.body.id;
var fn = req.body.f;
var ln = req.body.l;
var email = req.body.e;

var query = 'UPDATE stu SET email=?,firstname = ?,lastname=?  WHERE id=?';
    //var up = 'insert into stu(id,email,firstname,lastname)values(?,?,?,?)';
client.execute(query, [email,fn,ln,id], function (err, result) {
    if (err) {
        res.status(404).send({msg: err});
    } else {
        res.send(result);
    }
});
});

标签: expresscassandra

解决方案


When you're updating the row, you need to specify all components of the primary key - in your case this is id & email, but you're specifying only the id.

From documentation:

The WHERE clause specifies the row or rows to be updated. To specify a row, the WHERE clause must provide a value for each column of the row's primary key. To specify more than one row, you can use the IN keyword to introduce a list of possible values. You can only do this for the last column of the primary key.


推荐阅读