What is the currently acceptable syntax for sending a CREATE script from Node.js to Neo4j in 2022 and after?
I am getting several errors trying to pass in dynamic props from form input fields.
I need to create a new record from my form inputs using Node.js.
This is an example of a syntax that is no longer accepted:
app.post('/books/add', function(req, res){
var title = req.body.title;
var year = req.body.year;
session
.run('CREATE(n:Book {title: {paramTitle}, year: {paramYear}}) RETURN n:title', {paramTitle:title, paramYear:year})
.then(
function(result){
res.redirect('/');
session.close();
}
)
.catch(function(error){
console.log(error)
});
res.redirect('/');
});
The syntax you're using is deprecated. Parameters are now identified with the dollar symbol $ instead of curly brackets {}. That means you need to update your query to:
.run(
'CREATE(n:Book {title: $paramTitle, year: $paramYear}) RETURN n:title',
{
paramTitle: title,
paramYear: year
}
)
See relevant documentation here: https://neo4j.com/docs/cypher-manual/current/syntax/parameters/