请求成功/失败时,使用Neo4j返回布尔值

时间:2018-11-22 19:00:55

标签: neo4j cypher

我正在尝试进行查询,查询成功或失败时将返回一个布尔值。因此,成功时将为true,失败时将为false:

这是我的要求,在RETURN之后,我尝试了neo4j

MATCH (n:User),(d:Song) 
WHERE n.username = "syord" 
  AND d.title = "Hello" 
CREATE (n)-[r:PURCHASED]->(d) 
SET n.totalStars = 999999  
RETURN CASE 
WHEN n IS NULL 
  THEN false 
  ELSE true 
END 
AS n

成功时返回true,但失败时我什么也没得到:(no changes, no records)

1 个答案:

答案 0 :(得分:2)

基本思想

MATCH (n:YourLabel) RETURN count(n)>0 AS result;

结果

╒════════╕
│"result"│
╞════════╡
│false   │
└────────┘

应用于您的具体查询

MATCH (n:User),(d:Song) 
WHERE n.username = "syord" 
  AND d.title = "Hello" 
CREATE (n)-[r:PURCHASED]->(d) 
SET n.totalStars = 999999  
RETURN count(n)>0
AS n