知识库

调用 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;

将创建 id=123 且 name='Emil Eifrem' 的 :Person 节点。

但是,如果您想提供更大的灵活性,通过参数传递 idname 的值,可以通过更改 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;
© . All rights reserved.