[英]How to update node node with node.js?
I cannot update the node in the database with neo4j.the update process does not occur. 我无法使用neo4j更新数据库中的节点。更新过程不会发生。 If the problem is not the question of the code, I could not figure out the writing of the code.
如果问题不是代码的问题,我将无法弄清楚代码的编写。
app.post('/Movie/update',function(req, res){
var title = req.body.title;
var title = req.body.title2;
session
.run('MATCH (n:Movie {title:{titleParam}}) SET n.title={titleParam} RETURN n',{titleParam:title, title2Param:title})
.then(function(result){
res.redirect('/');
session.close();
})
.catch(function(err){
console.log(err);
});
res.redirect('/');
});
HTML code: HTML代码:
<form method="POST" action="/movie/update">
<br>
<input type="text" name="title">
<input type="text" name="title2">
<br>
<input type="submit" value="Submit">
</form>
In addition to @jfriesenhahn's answer, your Javascript code is also assigning 2 different values to the same title
variable. 除了@jfriesenhahn的答案外,您的Javascript代码还为同一个
title
变量分配了2个不同的值。 You should use 2 different variables: 您应该使用2个不同的变量:
var title = req.body.title;
var title2 = req.body.title2;
session
.run('MATCH (n:Movie {title: $title}}) SET n.title= $title2 RETURN n',
{title: title, title2: title2})
or, more simply: 或者,更简单地说:
session
.run('MATCH (n:Movie {title: $title}}) SET n.title= $title2 RETURN n',
{title: req.body.title, title2: req.body.title2})
This answer also uses the now-preferred $foo
syntax for parameters (instead of the deprecated {foo}
syntax). 此答案还对参数使用了现在首选的
$foo
语法(而不是不建议使用的{foo}
语法)。
So, it may just be a typo on your part, but you are using titleParam
twice. 因此,这可能只是您的错字,但是您两次使用
titleParam
。 I think they cypher you are looking for is: 我认为您正在寻找的密码是:
MATCH (n:Movie {title:{titleParam}}) SET n.title={title2Param} RETURN n
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.