用条件更改属性

时间:2015-09-11 20:07:35

标签: neo4j cypher

查询应检查关系是否已存在,在这种情况下应检查属性是否具有特殊值并根据检查进行更改。如果该关系不存在,则应创建。

我尝试了几种方法,最接近的是

MERGE (u:User {uuid: {userUUID}}) -[r:relation {rType: {rType}}]-> (n:Node)
ON CREATE SET 
    r.uuid = {relUUID},
    r.status = {relStatus}
ON MATCH SET
    r.status = {relStatus}
    WHERE r.status = "1"   // Only if r.status of the existing pattern is 1 it shall be changed to the value of relStatus
RETURN r

WHERE没有正确的语法 - 也许有人提示我如何检查属性,并且只在使用ON MATCH时根据特殊触发器更改属性。

感谢。

1 个答案:

答案 0 :(得分:1)

这应该有效:

MERGE (u:User {uuid: {userUUID}}) -[r:relation {rType: {rType}}]-> (n:Node)
ON CREATE SET 
    r.uuid = {relUUID},
    r.status = {relStatus}
ON MATCH SET
    r.status = CASE WHEN r.status = "1" THEN {relStatus} ELSE r.status END
RETURN r;