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.

Updating a field with APOC CSV

I have a field in my db that needs to be updated from a CSV file. The CSV file itself is rather long but in a simple format with a name, a node id, and a level. APOC is not my usual.

The CSV

'prog_name','node','level'
'dirielfran_apuntes.2021-02-27.java',2001,6
'dirielfran_apuntes.2021-02-27.java',3001,6
'dirielfran_apuntes.2021-02-27.java',3002,6
'dirielfran_apuntes.2021-02-27.java',4001,2
'dirielfran_apuntes.2021-02-27.java',5001,4
'dirielfran_apuntes.2021-02-27.java',5002,4
'dirielfran_apuntes.2021-02-27.java',5010,4
'dirielfran_apuntes.2021-02-27.java',6001,6
'dirielfran_apuntes.2021-02-27.java',7001,10

in Cypher this would be match (a {progname:'dirielfran_apuntes.2021-02-27.java', inode:2001}) set a.level = 6 return count(a)

But there are a lot of these so APOC seems to be the way to go on this with an iterate so it gets committed frequently

CALL apoc.periodic.iterate('
CALL apoc.load.csv( 'ProgLevel.csv', {skip:1, limit:1, header:true],
MATCH (p:ProgNode {progname:row.prog_name, inode: row.node ) SET p.level = row.level
', {batchSize:10000, iterateList:true, parallel:true});

What is wrong with my APOC

1 ACCEPTED SOLUTION

What error are you getting?

I think you need something like this either way:

CALL apoc.periodic.iterate(
  'CALL apoc.load.csv( 'ProgLevel.csv', {skip:1, limit:1, header:true}) 
   YIELD map as row',
  'MATCH (p:ProgNode {progname:row.prog_name, inode: row.node} ) 
   SET p.level = row.level',
 {batchSize:10000, iterateList:true, parallel:true}
);

View solution in original post

3 REPLIES 3

Still looking for some help on this one. Thanks

What error are you getting?

I think you need something like this either way:

CALL apoc.periodic.iterate(
  'CALL apoc.load.csv( 'ProgLevel.csv', {skip:1, limit:1, header:true}) 
   YIELD map as row',
  'MATCH (p:ProgNode {progname:row.prog_name, inode: row.node} ) 
   SET p.level = row.level',
 {batchSize:10000, iterateList:true, parallel:true}
);

That worked perfectly thank you.

The issue turned out to be a combination of factors. There seems to be an inconsistency in the APOC.CONF and normal CONF that was biting us at first

One of these lines is from the documentation, one from the error message.

apoc.import.file.enabled=true
apoc.file.import.enabled=true

and the other was just tricky syntax although from your response, your indentation was helpful.
Thank you

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online