cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Load data from CSV and connect nodes to a single parent node

Hi, I'm new to Cypher and I'd like to create a couple hundred new nodes from a CSV file and branch these off from a single parent node. What Cypher statement can I use to create the single parent node and then upload and link the CSV data? I'm thinking something like this: LOAD CSV FROM 'https://data.neo4j.com/bands/artists.csv' AS line CREATE (n:Artists)-[:ARTIST]->(:Artist {name: line[1], year: toInteger(line[2])})

Am not sure how to create the single parent node and relationships which the CSV data will create?

1 REPLY 1

You could create the node before the import and ‘match’ to retrieve it in the query, or ‘merge’ it in the query to ‘create’ it if it doesn’t exist and match it to retrieve it

Try the following, assuming it was already created and has ‘id’ property of 100.  Substitute any predicate that works. 

 

Match (n:Artist{id:100})

with n

LOAD CSVFROM 'https://data.neo4j.com/bands/artists.csv'AS line

merge (n)-[:ARTIST]->(:Artist{name: line[1], year: toInteger(line[2])}