1

I am trying to create nodes by loading a csv file. Since I wanted to exclude some columns I decided to use apoc.load.csv instead of the simpler LOAD CSV command.

I wanted to have all the columns present as corresponding property value for the nodes. However I am not able to figure out how to do it. When the columns are less you can hardcode it, but in my real dataset I have more than 60 columns so I was hoping that there would be a programmatic way to achieve what I want to do.

Demo Dataset you can use data.csv -

name,age,beverage,country_from,fruit
Selma,9,Soda,RU,Apple
Rana,12,Tea,USA,Orange
Selina,19,Cola,CA,Guava

What I have tried so far that doesn't work yet -

CALL apoc.load.csv('data.csv', {header:true, ignore:['beverage'], 
mapping:{
    age: {type:'int'},
    country_from: {name: "country"}
    }
})
YIELD map as row
CREATE (e:Entity $row)
CREATE (f:Fruit {name: row.fruit})
CREATE (c:Country {name: row.country_from})
MERGE (e:Entity)-[:EATS]->(f:Fruit)
MERGE (e:Entity)-[:IS_FROM]->(c:Country)
RETURN e,c,f

Expected Output:
The graphdatabase has the Entity nodes with properties name,age,country,fruit

Initially I was using {row} but then I got the error as described here

The old parameter syntax `{param}` is no longer supported. Please use `$param` instead

so I switched to using $row but then I get -

Expected parameter(s): row

I have followed the ideas from the following links -

  1. https://neo4j-contrib.github.io/neo4j-apoc-procedures/3.4/export-import/load-csv/
  2. https://neo4j.com/labs/apoc/4.1/import/load-csv/
jar
  • 2,646
  • 1
  • 22
  • 47

0 Answers0