0
votes

I want to import some different types of nodes in neo4j where the nodes only differ on the type and not the data. Is it possible to import something like this:

NodeType,Id,Name
NodeX,1,Yolo
NodeY,2,World

And get two nodes, one of type NodeX and one of type NodeY somehow?

What I would like to write is something like this:

LOAD CSV WITH HEADERS FROM "file:///nodes.csv" as row
WITH row WHERE row.Id IS NOT NULL
MERGE (c:row.NodeType {id: row.Id, name: row.Name});
1

1 Answers

0
votes

You can use the APOC procedure apoc.merge.node to do the equivalent of MERGE for nodes with dynamically-assigned labels:

LOAD CSV WITH HEADERS FROM "file:///nodes.csv" as row
WITH row WHERE row.Id IS NOT NULL
CALL apoc.merge.node([row.NodeType], {id: row.Id, name: row.Name}) YIELD node
RETURN node