4
votes

I am trying to create some unique relationships between entities in neo4j. Right now I have authors and articles, with a Authored relationship between them. I want to create a CoAuthored relationship between the entities

Like so

match (a)-[r]->(b)<-[r2]-(c)
create (a)-[new:CoAuthor]->(c)

However, I would like to create a unique co-author relationship, but update the weight if it already exists. I saw this postm but the syntax is no longer supported In Cypher, how can I create a relationship if it doesn't exist; update property if it does

SyntaxException: This syntax is no longer supported (missing properties are now returned as null). Please use (not(has(<ident>.weight)) OR <ident>.weight=<value>) if you really need the old behavior.

I do not quite understand what it is that I am replacing. I looked at the Merge command, but can't quite get it to work

1

1 Answers

3
votes

You should be able to replace create with merge in this particular case.

match (a)-[r]->(b)<-[r2]-(c)
merge (a)-[new:CoAuthor]->(c)
on create set new.weight=1
on match set new.weight=new.weight+1