Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...