0

I am trying to load the node from csv in Neo4j, however, every time I try to do this I get such an error:

Neo.ClientError.Statement.ExternalResourceFailed: Couldn't load the external resource at: file:/var/lib/neo4j/import/events.csv

My event.csv file is in /var/lib/neo4j/import directory with 777 permissions. The query I try to run looks like this:

USING PERIODIC COMMIT 500 LOAD CSV WITH HEADERS FROM "file:///events.csv"  AS line
CREATE (e:Event { event_id: toInteger(line.event_id), 
created: line.created,
description: line.description })

I set up Neo4j using the latest version of docker image. What might be wrong with file permissions or file location?

Cassie
  • 339
  • 1
  • 3
  • 13

2 Answers2

2

Docker container cannot get access to files outside on the host machine, unless you mount those files to the container.

Solution is to bind-mount the directory to your container when calling the docker run command:

docker run -v /var/lib/neo4j/import:/var/lib/neo4j/import ... <IMAGE> <CMD>
Yuankun
  • 6,875
  • 3
  • 32
  • 34
  • I've tried to run this: `docker run -v /var/lib/neo4j/import:/var/lib/neo4j/import \ --publish=7474:7474 --publish=7687:7687 \ --volume=$HOME/neo4j/data:/data \ --volume=$HOME/neo4j/conf:/conf \ --env=NEO4J_dbms_allow_upgrade='true' \ --env=NEO4J_dbms.security.allow_csv_import_from_file_urls='true' \ neo4j:latest` but I've got another weird error: `ERROR Neo4j cannot be started because the database files require upgrading and upgrades are disabled in the configuration. Please set 'dbms.allow_upgrade' to 'true' in your configuration file and try again.` – Cassie Mar 21 '18 at 16:30
0

In addition to mounting the "dataimport" volume when running the container, make sure you have the following configuration in the neo4j.conf file in conf dir:

server.directories.import=/var/lib/neo4j/import
dbms.security.allow_csv_import_from_file_urls=true

This is my docker run command:

docker run \
    --restart always \
    --detach \
    --publish=7474:7474 --publish=7687:7687 \
    --env NEO4J_PLUGINS='["apoc", "graph-data-science", "bloom"]' \
    --volume=/opt/neo4j/data:/data \
    --volume=/opt/neo4j/logs:/logs \
    --volume=/opt/neo4j/conf:/conf \
    --volume=/opt/neo4j/import:/var/lib/neo4j/import \
    --env NEO4J_AUTH=neo4j/my_password\
    neo4j:5.9.0
Juampa
  • 154
  • 1
  • 7