VINNUSAURUS
VINNUSAURUS

Reputation: 1558

How to return values after deleting relationship in neo4j

How can I return the values of nodes and relationships after deleting a relationship

Cypher:

MATCH (p:Person)-[t:LIKED]->(a:Post) WHERE p.identity='kOo08cpMoYPWwnwB4XMZ3CbTRcO2' AND a.uuid='b60f773d-6d85-48bc-9900-8037c4b2c0b2' DELETE t WITH p,a MATCH (a)<-[l:LIKED]-() RETURN count(l) AS likes, exists((p)-[:LIKED]->(a)) AS liked, a.uuid AS uuid

the above query always returns [] , p and a nodes do exist.

Upvotes: 0

Views: 189

Answers (1)

alex4532
alex4532

Reputation: 141

Looks like the second MATCH doesn't find any matches. Try to use the OPTIONAL MATCH statement:

MATCH (p:Person)-[t:LIKED]->(a:Post)
WHERE p.identity='kOo08cpMoYPWwnwB4XMZ3CbTRcO2' AND a.uuid='b60f773d-6d85-48bc-9900-8037c4b2c0b2'
DELETE t
WITH p,a
OPTIONAL MATCH (a)<-[l:LIKED]-()
RETURN count(l) AS likes, exists((p)-[:LIKED]->(a)) AS liked, a.uuid AS uuid

Upvotes: 1

Related Questions