首页 > 解决方案 > Neo4j - 删除节点

问题描述

在我的 Neo4j 数据库中,有些节点的ref字段的值等于其他节点中存在的id字段。换句话说,它是一个 XML 文件,其中一些节点引用了其他节点。有没有办法删除这些节点?

标签: neo4jcypher

解决方案


如果我理解,您正在尝试删除一组节点,其ref属性值等于id另一组节点的属性之一。如果是这样,您可以使用这样的 Cypher 查询来执行此操作:

match (n1:Node)
// store all ids into a collection called 'ids'
with collect(distinct n1.id) as ids

// match all nodes that 'ref' property equal to any value in 'ids' 
match (n2:Node)
where n2.ref in ids

// delete all n2 nodes and its relationships
detach delete n2

推荐阅读