简体   繁体   English

neo4j Javascript API:创建参数

[英]neo4j Javascript API : create parameter

I am trying to create a parameter from a Javascript application我正在尝试从 Javascript 应用程序创建参数

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我仔细检查了 json_table_definition 参数中的值,它很好来自 neo4j 的相同命令

:param is just a neo4j Browser command, and is not in the Cypher language. :param只是一个 neo4j 浏览器命令,不在 Cypher 语言中。

You actually already know how to passparameters , since your run() invocation is actually passing json_table_definition as a parameter.您实际上已经知道如何传递参数,因为您的run()调用实际上是将json_table_definition作为参数传递。 You just need to specify a legal Cypher query to use that parameter.您只需指定合法的 Cypher 查询即可使用该参数。

For example (with a random Cypher query):例如(使用随机 Cypher 查询):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM