Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to DELETE nodes or relationship with NULL properties in neo4j 2.0 with cypher

Tags:

neo4j

cypher

I have created some nodes and relationships within these. But while doing these something wrong happened. I want to delete all nodes having "SGS", except node with ID 2.

Following is script I ran to create node and relationships:

(Please also suggest how to EDIT this one, if possible)

I tried DELETE (along with match, where, IS NULL, etc) with some different trial and error methods but unable to achieve same. Please Help.

like image 271
ShreyansS Avatar asked Jan 06 '14 11:01

ShreyansS


2 Answers

It looks like all your nodes have a name, except the node that you want deleted. So you can try

match n
WHERE NOT (HAS (n.name)) //find all nodes with no name property
with n
match n-[r]-() //find all nodes connected to that node
delete r,n //delete its relations and then the node itself

(note not tested)

Looks like in your create statement above, you've use (rkn) instead of (rk) and also probably (answ) instead of something else. So (rkn)-[:READ]->(bk1) will just create a node with no properties to represent rkn and a READ relation to OneNight@CallCenter. You just have to verify and fix those.

e.g. the relationships all refer to a node called (rkn) so I renamed the rk node in your create statement to rkn. Please also verify that every node you refer to in your relationships actually maps to a node in your create statement.

NOTE: HAS is no longer supported in Cypher, please use EXISTS instead!

like image 187
Luanne Avatar answered Sep 29 '22 07:09

Luanne


This one worked for me

match (n) WHERE NOT (EXISTS (n.name)) DETACH DELETE n
like image 24
jandraor Avatar answered Sep 29 '22 07:09

jandraor