我正在尝试在 neo4j 中的实体之间创建一些独特的关系。现在我有作者和文章,它们之间有 Authored 关系。我想在实体之间创建 CoAuthored 关系
像这样
match (a)-[r]->(b)<-[r2]-(c)
create (a)-[new:CoAuthor]->(c)
但是,我想创建一个独特的共同作者关系,但如果它已经存在则更新权重。我看到了这个 postm 但不再支持语法 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.
我不太明白我要替换的是什么。我查看了 Merge 命令,但无法使其正常工作
最佳答案
您应该可以替换 create
与 merge
在这种特殊情况下。
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
关于neo4j - 如何创建独特的关系 neo4j 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20944812/