密码删除节点和所有相关节点的列表 [英] cypher delete node and all the list of related node
问题描述
我正在尝试删除从给定节点开始到列表末尾的整个列表。
I'm trying to delete an entire list starting from a given node to the end of the list.
这里是根,关系和子节点的列表。子节点可以具有不确定的节点。
Where is the list of the root,relationship and child nodes. The child nodes can have an undetermined nodes.
(r:Root {name:'masterDoc'})<-[p:previous]<-(s1:schema)<-[p1:previous]<-(s2:schema)<-[pn:previous]<-(sn:Schema)
当我在下面运行密码查询时,我发现类型不匹配:预期的节点,路径或关系,但是是集合
When I run the cypher query below I'm getting a Type mismatch: expected Node, Path or Relationship but was Collection
MATCH (n:`Root` {name:'masterDoc'})-[r:previous*]-(s) delete s,r,n
任何想法?
推荐答案
您想要拉出最长的节点路径,遍历关系并删除每个关系,然后遍历节点并删除它们。
You want to pull out the longest path of nodes, iterate over the relationships and delete each one and then iterate over the nodes and delete them.
更新后的答案
自发布此答案以来,对Cypher的改进现在允许使用单个命令分离和删除节点。
Improvements to Cypher since this answer was posted allow now for nodes to be detached and deleted with a single command.
// match the path that you want to delete
MATCH p=(:Root {name: 'masterDoc'} )-[:previous*]->()
WITH p
// order it in descending order by length
ORDER by length(p) desc
// grab the longest one
LIMIT 1
// delete all of the relationships and their nodes
DETACH DELETE p
旧答案
注意: 这是假定路径中的每个节点都不再锚定到路径中的节点以外的其他位置,否则将无法删除它们。
NOTE: This assumes that each node in the path is no longer anchored to anything other than the nodes in the path otherwise they will not be able to be removed.
// match the path that you want to delete
match p=(:Root {name: 'masterDoc'} )-[:previous*]->()
with p
// order it in descending order by length
order by length(p) desc
// grab the longest one
limit 1
// delete all of the relationships
foreach (r in relationships(p) | delete r)
// delete all of the remaining nodes
foreach (n in nodes(p) | delete n)
这篇关于密码删除节点和所有相关节点的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!