How to DELETE nodes or relationship with NULL prop

2019-04-28 16:28发布

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.

标签: neo4j cypher
2条回答
太酷不给撩
2楼-- · 2019-04-28 16:58

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!

查看更多
相关推荐>>
3楼-- · 2019-04-28 17:07

This one worked for me

match (n) WHERE NOT (EXISTS (n.name)) DETACH DELETE n
查看更多
登录 后发表回答