Delete all relations and connected nodes in Neo4j for a user

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-01 16:37:24

问题


We have selected neo4j as the DB for our web application. The user has a large number of relations and connected nodes. As of now there are about 20 relations for a user. One of the features is a newsfeed feature. If i want to delete a user completely, is the cypher query the best way to delete or is there any other alternative?

Since we are still planning to add new features, the relationships and nodes connected to the user also will increase. So if we use cypher query, the query has to be modified for every new relationship added. Please advise.

Thanks, Pavan


回答1:


Yes, you can use Cypher to remove a user. Of course, there are alternative methods, depending on the language or framework you're using with your web application. If you like to have advise on that, please specifiy how you're using Neo4j in detail.

Note that you have to remove all relationships (outgoing and incoming) first in order to be able to remove the node.

Example:

START n = node(3)
MATCH n-[r]-()
DELETE n, r

This example was taken from the official manual: http://docs.neo4j.org/chunked/milestone/query-delete.html




回答2:


As of Neo4j 2.3 there is another way to do this:

MATCH (n { name:'Andres' })
DETACH DELETE n

I found this example in the documentation at: http://neo4j.com/docs/stable/query-delete.html




回答3:


An alternative could be to write a gremlin script that traverses your graph starting with your user and is putting in two collection the relationships and the nodes that you intend to delete. If you want to delete everything, perhaps you can implement your depth first traversal in Gremlin and delete while traversing.



来源:https://stackoverflow.com/questions/15283743/delete-all-relations-and-connected-nodes-in-neo4j-for-a-user

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