javascriptneo4jcypherneo4j-driver

neo4j Javascript API : create parameter


I am trying to create a parameter from a Javascript application

But the following code doesn't work :

var input=json_table_definition.replace(/[\n\r]+/g, '');    
  var session = driver.session();
  let results;

  return  session
    .run(':param jsonTable=>$json_table_definition',
        {json_table_definition:input}
    )
    .then(result => {
      session.close();


    })
    .catch(error => {
      session.close();
      results=[];
      throw error;
    });

I get the following error in the browser:

XXXXX Uncaught (in promise) Neo4jError: Invalid input ':': expected <init> (line 1, column 1 (offset: 0))
":param jsonTable=>$json_table_definition"
 ^ 

I double checked the value in the json_table_definition parameter and it's fine The same command from the neo4j


Solution

  • :param is just a neo4j Browser command, and is not in the Cypher language.

    You actually already know how to pass parameters, since your run() invocation is actually passing json_table_definition as a parameter. You just need to specify a legal Cypher query to use that parameter.

    For example (with a random Cypher query):

    ...
    .run('MATCH (n:Foo) WHERE n.def = $json_table_definition RETURN n',
        {json_table_definition: input}
    )
    ...