How to delete nodes recursively from a start node

℡╲_俬逩灬. 提交于 2019-12-12 04:49:20

问题


I have a graph which has a set of nodes and its children. There is a root node from where the rest of the nodes branch out. There are few sets of such node collection.

I want to pick a root node and clear all its connections and nodes recursively, leaving the root node for future additions.

       start n=node:DataSpace(DataSpaceName="DS1") match (ds)-[r]-(e) delete e,r

The above Query is definitely wrong, as it does not consider recursion and also the condition that entities have to be deleted before deleting the relations.

Any suggestions on how to achieve the same.

Also, since I will be using neo4JClient, it will be great if we have a neo4jClient translation as well.


回答1:


You want to do something like

MATCH (n:MyLabel)-[r*]-(e)
FOREACH (rel IN r| DELETE rel)
DELETE e

See http://console.neo4j.org/r/8go5i6 for an example.




回答2:


"The condition that entities have to be deleted before relations"

AFAIK deleting a node that has relations will trigger an error.

Why not adding depth for your relations to include recursivity ?:

MATCH (n:MyLabel)-[r*]-(e) DELETE r,e


来源:https://stackoverflow.com/questions/25101026/how-to-delete-nodes-recursively-from-a-start-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!