花了一些时间弄清楚如何轻松删除断开连接的节点,但我无法“保留”它们。在Neo4j中轻松删除断开连接的节点2.1.0-M01
match (n)-[r]-(m) where r is null delete n
显然是行不通的,无论它
match (n) optional match (n)-[r]-(m) where r is null delete r
那么,什么是做到这一点的最好方法是什么?
花了一些时间弄清楚如何轻松删除断开连接的节点,但我无法“保留”它们。在Neo4j中轻松删除断开连接的节点2.1.0-M01
match (n)-[r]-(m) where r is null delete n
显然是行不通的,无论它
match (n) optional match (n)-[r]-(m) where r is null delete r
那么,什么是做到这一点的最好方法是什么?
这个怎么样?
MATCH (n)
WHERE NOT n--()
DELETE n
也许是一个解决办法,但我终于做了这个
match (n)-[r]-(m)
set n.x=1
这将为所有相关节点的属性ñ
然后
match (n) where n.x is null delete n
删除松散节点和
match (n) remove n.x
清理。不知道这是否是个好习惯,但
这样做相当昂贵。也只适用于小图。 –
另一个想法:
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
短而快。谢谢 – Graphileon