Neo4j Desktop导入CSV数据文件

2018-04-28  本文已影响0人  rockmatrix

安装了neo4j Desktop来学习neo4j的Cypher语言,在导入csv文件时,输入以下语句执行后出错了,原因是未知协议

LOAD CSV FROM 'E:/Data/neo4j/csv/artists.csv' AS line
CREATE (:Artist { name:line[1], year: toInteger(line[2])})

后来知道读取本地文件需要用file:///,于是修改一下:

LOAD CSV FROM 'file:///E:/Data/neo4j/csv/artists.csv' AS line
CREATE (:Artist { name:line[1], year: toInteger(line[2])})

还是出错了:

Neo.ClientError.Statement.ExternalResourceFailed: Couldn't load the
external resource at:
file:/C:/Users/18043380/.Neo4jDesktop/neo4jDatabases/database-4be0c9dd-5fb6-4c27-83eb-62299a08bcb9/installation-3.3.5/import/Data/neo4j/csv/artists.csv

neo4j官网上的指南LOAD CSV,提到

dbms.directories.import
Sets the root directory for file:/// URLs used
with the Cypher LOAD CSV clause. This must be set to a single
directory on the filesystem of the database server, and will make all
requests to load from file:/// URLs relative to the specified
directory (similar to how a Unix chroot operates). The default value
is import. This is a security measure which prevents the database from
accessing files outside the standard import directory. Setting
dbms.directories.import to be empty removes this security measure and
instead allows access to any file on the system. This is not
recommended.

在Desktop中的Database的Setting中找到这句:

dbms.directories.import=import
Neo4j Desktop中Database设置

再看上面出错加粗的文字,发现一点端倪,这个import目录是配在Database中的,那么Desktop软件中肯定有入口打开它,果然就在Database界面中Open Folder按钮,可以打开这个Database的根目录,将文件放入import中即可导入。

打开Database的Import文件夹

将persons.csv放入Import目录中

persons.csv文件内容

通过LOAD CSV导入persons.csv

导入CSV文件的Cypher语句

返回结果如下:

导入之后生成的node
上一篇下一篇

猜你喜欢

热点阅读