cypher delete node and all the list of related nod

2019-05-29 21:10发布

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

Any Idea? 

标签: cypher
1条回答
劳资没心,怎么记你
2楼-- · 2019-05-29 21:53

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.

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)
查看更多
登录 后发表回答