4

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

Community
  • 1
  • 1
Mark C
  • 427
  • 2
  • 7
  • 16

1 Answers1

3

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
Eve Freeman
  • 32,467
  • 4
  • 86
  • 101
  • 1
    Merge does not seem to guarantee uniqueness. I ran a lot of these queries really fast and it still created duplicated relationships. Am I missing something trivial here? – yuklai Dec 23 '15 at 01:04