如何使用cypher删除neo4j 2.0中的节点或具有NULL属性的关系 [英] How to DELETE nodes or relationship with NULL properties in neo4j 2.0 with cypher

查看:512
本文介绍了如何使用cypher删除neo4j 2.0中的节点或具有NULL属性的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在其中创建了一些节点和关系.但是,在执行这些操作时,发生了一些错误.我想删除所有具有"SGS"的节点,ID为2的节点除外.

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)

我尝试了DELETE(以及match,where,IS NULL等),但尝试了一些不同的尝试和错误方法,但无法实现相同的目标.请帮忙.

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

推荐答案

除了要删除的节点外,所有节点都具有名称. 所以你可以尝试

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

(注释未经测试)

就像上面的create语句一样,您使用(rkn)代替(rk),还可能使用(answ)代替了其他东西.因此,(rkn)-[:READ]->(bk1)将只创建一个没有属性来表示rkn的节点,并创建与OneNight @ CallCenter的READ关系​​.您只需要验证并修复这些问题即可.

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.

例如这些关系都引用了一个名为(rkn)的节点,因此我在您的create语句中将rk节点重命名为rkn.还请确保您在关系中引用的每个节点都确实映射到create语句中的一个节点.

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.

注意:Cypher不再支持HAS,请改用EXISTS!

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

这篇关于如何使用cypher删除neo4j 2.0中的节点或具有NULL属性的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆