GvanJoic
GvanJoic

Reputation: 213

Update property value in Neo4j on import

I have the following code for importing data in CSV. The data is of the form A-[:LIKES {times: x}]-B where x is a number. However when importing, I am stuck on how to update the value of times if the relationship is found again. There seems to be a SET function that allows you to do so, but I can't get to place it properly.

LOAD CSV FROM 'file:///home/gvanjoic/file.csv' AS line
MERGE (n:A {number : line[0]})
WITH line, n
MERGE (m:B {ID : line[1]})
WITH m,n
MERGE (n)-[:LIKES]->(m);

Kindly help me update the value of of the property.

Thanks.

Upvotes: 1

Views: 300

Answers (1)

cybersam
cybersam

Reputation: 66999

[EDITED]

You should be able to do this:

LOAD CSV FROM 'file:///home/gvanjoic/file.csv' AS line
MERGE (n:A {number : line[0]})
WITH line, n
MERGE (m:B {ID : line[1]})
WITH m,n
MERGE (n)-[rel:LIKES]->(m)
ON CREATE SET rel.times = (CASE WHEN rel.times IS NULL THEN 0 ELSE rel.times END) + 1;

Upvotes: 2

Related Questions