2
votes

I would like to pass a variable (values from request body) as a parameter to the cypher query but i don´t know if (and how) this is possible. I´ve tried few things and a "normal" cypher query with hardcoded string parameter is working perfectly, but when I want to pass the variable as a parameter, I´ll get an error Structure(127, [[object Object]]). I´m on Neo4j 3.1. in combination with a node.js-server which builds the cypher queries.

This is a snippet..

var user_firstname = req.body.firstname;
var user_lastname = req.body.lastname;
var user_city = req.body.city;
session
    .run("CREATE (n:Person {firstname: {firstname}, lastname: {lastname}, city: {city}})", 
      { firstname: user_firstname, 
        lastname: user_lastname, 
        city: user_city })

Thanks in advance for your help, cheers!

1
Are all your user_* variables strings, or are some of them objects?cybersam
no, they´re all strings (some of them are ints..)Andy
Just to be sure -- are you saying that because that is the schema you expect, or have you actually verified that the response data conforms to the schema?cybersam
aaaaaah... thanks so much! your answer was a kind of advice for me! I´ve made a post with (name, lastname, city...) but the pattern expected inside the query is (FIRSTname, lastname, city...) ;) ThanksAndy

1 Answers

1
votes

In Neo4j 3.1 I believe parameter syntax was changed. Try using $ before the parameter instead of encasing it in brackets. See if this query will work instead:

CREATE (n:Person {firstname: $firstname, lastname: $lastname, city: $city})