Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

neo4j - How to create nodes with parameterized labels in Cypher

It has been a while (2 years) since that same question was asked. Back then, creating nodes or relationships with parameterized labels was not supported in Cypher. Is it better supported today?

What I want to accomplish is to simply to create nodes in Neo4J using Cypher, from a CSV file, providing that the file contains 2 columns, one for node type and one for node name:

  LOAD CSV WITH HEADERS FROM 'https://xyz/nodes.csv' AS line
  WITH line.type as label
  CREATE (:EVAL(label) { name: line.name })

Here is the link to the same question, asked 2 years ago.

question from:https://stackoverflow.com/questions/65645377/how-to-create-nodes-with-parameterized-labels-in-cypher

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

With pure Cypher you can't, but nowadays everybody use the APOC library with the apoc.create.node procedure :

LOAD CSV WITH HEADERS FROM 'https://xyz/nodes.csv' AS line
CALL apoc.create.node(['EVAL', line.type], {name: line.name})
YIELD node
RETURN node

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...