调用 apoc.cypher.runFile 时如何传递参数
APOC 允许使用存储过程 apoc.cypher.runFile 将文件内容提交给 Cypher 引擎执行。要在 conf/neo4j.conf 中读取该文件,需要先进行如下配置
apoc.import.file.enabled=true
随后如果定义一个文件,例如 import/myRunFile.cyp,并且文件内容如下所示
create (n:Person {id:123, name:'Emil Eifrem'});
通过 Cypher 运行时
call apoc.cypher.runFile("myRunFile.cyp",{}) yield row, result;
将创建一个标签为 :Person 的节点,属性为 id=123,name='Emil Eifrem'。
但是如果希望拥有更大的灵活性,能够通过参数传入 id 和 name 的值,可以通过修改 import/myRunFile.cyp 的内容,使其定义为下面的形式来实现
create (n:Person { id: $id_p1, name: $name_p2});
随后如下方式调用 apoc.cypher.runFile
call apoc.cypher.runFile("myRunFile.cyp",{parameters: {id_p1: 123, name_p2:'Emil Eifrem'}}) yield row, result;
此页面有帮助吗?