Neo4j - Remove nodes

时间:2018-05-14 17:38:30

标签: neo4j cypher

In my Neo4j database there are some nodes with the ref field with the value equal to the id field that is present in other nodes. In other words, it's an XML file with some nodes that reference other nodes. Is there a way to remove these nodes?

1 个答案:

答案 0 :(得分:0)

如果我理解,您正在尝试删除一组节点,其中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