Neo4j 2.1.0-M01中轻松删除未连接节点

3

花了一些时间想办法轻松删除断开连接的节点,但我无法找到它们。

match (n)-[r]-(m) where r is null delete n 

显然不起作用,也无法正常工作。
match (n) optional match (n)-[r]-(m) where r is null delete r

那么,最好的方式是什么?
3个回答

6
这个怎么样?
MATCH (n)
WHERE NOT n--()
DELETE n

1
另一个想法:

match (n)                     // match all nodes
with n
optional match (n)-[r]-()     // optionally match relationships
with n, count(r) as c
where c=0                     // filter those having no relationships
delete n                      // get rid of 'em

0

或许是一个变通方法,但我终于做到了这件事

match (n)-[r]-(m)
set n.x=1

这将为所有相关节点 n 创建属性

然后

match (n) where n.x is null delete n

删除松散的节点并

match (n) remove n.x  

清理一下。不知道这是否是一个好的做法。


做那件事情相当昂贵。而且只适用于小图。 - Michael Hunger

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接