apoc.cypher.runFiles
Procedure APOC Full
apoc.cypher.runFiles([files or urls],[{statistics:true,timeout:10,parameters:{}}])) - runs each statement in the files, all semicolon separated
Signature
apoc.cypher.runFiles(file :: LIST? OF STRING?, config = {} :: MAP?) :: (row :: INTEGER?, result :: MAP?, fileName :: STRING?)
Config parameters
The procedure support the following config parameters:
name | type | default | description |
---|---|---|---|
reportError |
boolean |
false |
Returns a entry row with key |
statistics |
boolean |
true |
Returns an additional row with the query statistics, leveraging the |
timeout |
long |
10 |
The single query timeout (in seconds) |
queueCapacity |
long |
100 |
The capacity of the |
parameters |
Map<String, Object> |
Empty map |
Optional parameter map to be used with the |
Reading from a file
By default importing from the file system is disabled.
We can enable it by setting the following property in apoc.conf
:
apoc.import.file.enabled=true
If we try to use any of the import procedures without having first set this property, we’ll get the following error message:
Failed to invoke procedure: Caused by: java.lang.RuntimeException: Import from files not enabled, please set apoc.import.file.enabled=true in your apoc.conf |
Import files are read from the import
directory, which is defined by the dbms.directories.import
property.
This means that any file path that we provide is relative to this directory.
If we try to read from an absolute path, such as /tmp/filename
, we’ll get an error message similar to the following one:
Failed to invoke procedure: Caused by: java.lang.RuntimeException: Can’t read url or key file:/path/to/neo4j/import/tmp/filename as json: /path/to/neo4j//import/tmp/filename (No such file or directory) |
We can enable reading files from anywhere on the file system by setting the following property in apoc.conf
:
apoc.import.file.use_neo4j_config=false
Neo4j will now be able to read from anywhere on the file system, so be sure that this is your intention before setting this property. |
Usage Examples
The examples in this section are based on the following file:
CREATE (n:Node {id:1});
MATCH (n:Node {id:1})
SET n.city = "London";
We can run the Cypher commands in create.cypher
and update.cypher
, by running the following query:
CALL apoc.cypher.runFiles(["create.cypher", "update.cypher"]);
row | fileName |
---|---|
result |
-1 |
create.cypher |
{constraintsRemoved: 0, indexesRemoved: 0, nodesCreated: 1, rows: 0, propertiesSet: 1, labelsRemoved: 0, relationshipsDeleted: 0, constraintsAdded: 0, nodesDeleted: 0, indexesAdded: 0, labelsAdded: 1, relationshipsCreated: 0, time: 0} |
-1 |
update.cypher |
We can see the contents of the database, by running the following query:
MATCH (n:Node)
RETURN n;
n |
---|
(:Node {city: "London", id: 1}) |
If we don’t want to see statistics for each Cypher statement, we can set statistics: false
:
CALL apoc.cypher.runFiles(["create.cypher", "update.cypher"], {statistics: false});
row | fileName |
---|