Search code examples
csvdockerneo4jneo4j-driver

Loading a CSV file into Neo4J running in Docker


I have Neo4J running in Docker (Windows 10). I want to import a large CSV file into it, using Node and neo4j-driver.

My query is (limited to 5 rows, for testing purposes):

let csvPath = 'file:///C:/Users/Test/largefile.csv';

let query = `
  USING PERIODIC COMMIT
  LOAD CSV FROM '${csvPath}' AS line
  WITH line LIMIT 5
  MERGE (:Person {name: line[1]})-[:connected_to]->(:Person {name: line[2]})
`;

No matter what I try to put in the path, the driver keeps looking for file:/var/lib/neo4j/import/C:/Users/Test/largefile.csv.

I tried with/without drive letter; tried local file and using ./; tried diffrent paths - the driver always looks for the file at /var/lib/neo4j/import even though I have no such folder on my machine.

Is it possible to import the file from my host machine, or will I need to copy it into the Docker container, into that folder structure?


Solution

  • You will need to copy it into the docker container or into a directory that is mapped into it; Neo4J by default only supports loading CSV from its import directory, and all LOAD CSV paths will be relative to that.

    This is with the out-of-the-box options; by modifying the dbms.directories.import variable in the config file, this can be changed, but it is explicitly not recommended by Neo4J documentation.