Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Delete a Node in Neo4j using Cypher Graph Query Language?

Tags:

neo4j

cypher

I want to Delete this Pessoa node and its relations to others,
but I don't want to delete the other nodes.

Node

This node has a Guid ID property with value c40f314f-0ecf-42e1-b44d-85b6d72f134a

I tried

MATCH (n {ID: 'c40f314f-0ecf-42e1-b44d-85b6d72f134a'}) DELETE n;

But this ERROR appears:

Neo.ClientError.Schema.ConstraintValidationFailed: Cannot delete node<35>, because it still has relationships. To delete this node, you must first delete its relationships.

like image 306
Tony Avatar asked Jan 29 '23 02:01

Tony


1 Answers

Using

MATCH (n {ID: 'c40f314f-0ecf-42e1-b44d-85b6d72f134a'}) DETACH DELETE n;

Deleted 1 node, deleted 2 relationships, completed after 2 ms.

Note that relationships of the node were removed as well.

like image 126
Tony Avatar answered Feb 08 '23 14:02

Tony