Neo4j: APOC - Caused by: java.io.RuntimeException: Can't read url or key file (No such file or directory)
I’ve been using Neo4j’s APOC library to load some local JSON files this week, and ran into an interesting problem.
The LOAD CSV
tool assumes that any files you load locally are in the import
directory, so I’ve got into the habit of putting my data there.
Let’s check what I’m trying to import by opening the import directory:
What’s in there?
Just the one JSON file needs processing. If we want to import local files we need to add the following property to our Neo4j configuration file:
apoc.import.file.enabled=true
If you’re using the Neo4j Desktop, you can add this property via the 'Settings' tab:
Once we’ve done that we’ll need to restart the database so our new settings will be picked up:
Now let’s try to process our JSON file:
neo4j> CALL apoc.load.json("file:///dummy.json");
Failed to invoke procedure `apoc.load.json`: Caused by: java.lang.RuntimeException: Can't read url or key file:/dummy.json as json: /dummy.json (No such file or directory)
Hmm, that didn’t work as we expected - it seems to be trying to read the file from the root of the machine rather than from the import
directory.
It turns out I hadn’t RTFM:
Let’s update our Neo4j configuration file to add the following property:
apoc.import.file.use_neo4j_config=true
If we re-run our query we’ll see that it now finds and processes the file:
About the author
I'm currently working on short form content at ClickHouse. I publish short 5 minute videos showing how to solve data problems on YouTube @LearnDataWithMark. I previously worked on graph analytics at Neo4j, where I also co-authored the O'Reilly Graph Algorithms Book with Amy Hodler.