Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete all relations and connected nodes in Neo4j for a user

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

like image 908
user2138493 Avatar asked Dec 27 '22 07:12

user2138493


1 Answers

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

like image 177
Axel Morgner Avatar answered May 16 '23 07:05

Axel Morgner