cancel
Showing results for 
Search instead for 
Did you mean: 

Params on javascript

arturo_guerrero
Node Clone

Hello,
I´m sure that someone of you can help me with this issue.
I´m trying to create a node property with "params", but I must be missing something, because nothing happens. I neither received a console.log error, nor the param is working properly.
I could console.log the requested variables, so that the request of the app is working, too.

Thank you for your help.

app.post("/person/originalname/add", function(req, res) {
var originalname = req.body.originalname;
var id = req.body.id;

session
.run("MATCH (n) where id(n) = $idParam SET n.original_name = $originalParam RETURN n", {
originalParam: originalname,
idParam: id
}
)
.then(function(result) {
res.redirect('/');

})
.catch(function(error) {
  console.log(error);
});

});

1 ACCEPTED SOLUTION

arturo_guerrero
Node Clone

I found the solution. In this case I needed to build a props{} to set it as property:

app.post("/person/originalname/add", function(req, res) {
var originalname = req.body.originalname;
var id = req.body.id;

session
.run("MATCH (n) where id(n) = $idParam SET n = $props", {
props: {
"original_name": originalname
},
idParam: id
})

.then(function(result) {
  res.redirect('/');

})
.catch(function(error) {
  console.log(error);

});

});

Thank you very much

View solution in original post

2 REPLIES 2

abk
Neo4j
Neo4j

Hi @arturo.guerrero ,

Tracking down these kinds of issues can be tricky. What happens when you directly run the query using Neo4j Browser? It can be helpful to debug in Neo4j Browser, both with and without parameters, then migrate the working query back into your app.

Best,
ABK

arturo_guerrero
Node Clone

I found the solution. In this case I needed to build a props{} to set it as property:

app.post("/person/originalname/add", function(req, res) {
var originalname = req.body.originalname;
var id = req.body.id;

session
.run("MATCH (n) where id(n) = $idParam SET n = $props", {
props: {
"original_name": originalname
},
idParam: id
})

.then(function(result) {
  res.redirect('/');

})
.catch(function(error) {
  console.log(error);

});

});

Thank you very much

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.