express - 我只想使用 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);
}
});
});
解决方案
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.
推荐阅读
- r - 使用 ggbiplot 绘制 PCA 会导致标签重叠。如何用 ggplot 用 PCA 绘图?
- docker - 防火墙运行时,ELK 容器无法在不同节点上连接
- database - 在 SQLite 中检查长度约束错误
- javascript - 引导导航栏下拉菜单/折叠的导航栏未打开
- python - 如何在Nifi中将参数传递给python脚本
- android - 如果我们必须在android中使用viewpager创建多个页面,那么我们是否必须创建多个片段?还有其他选择吗?
- android - 有没有办法为所有标签启用特定的 Android 日志级别(例如通过 adb)?
- java - 成员函数在 JAVA 中显示错误(intelliJ IDEA)
- python - 在 Python 中计算多个证券的对数回报
- python - 加入包含多个字典的多个列表以创建一个列表