Reputation: 504
I want to delete node if the node has no relationshops and return true, otherwise return false
match (p:Type {id:72})-->(x)
RETURN
CASE count(x)
WHEN 0 THEN DELETE p 'true'
ELSE 'false'
END AS deleted;
i always get invalid syntax. Is this possible in cypher?
Upvotes: 0
Views: 127
Reputation: 41706
Or
match (p:Type {id:72})
where not exists ((p)--())
delete p
Upvotes: 1
Reputation: 39925
To find nodes having no relationships you need to use OPTIONAL MATCH
and check for null after a WITH
:
match (p:Type {id:72})
optional match (p)-[r]-()
with p, r
where r IS null
delete p
Upvotes: 0