什么是通过ID删除节点的Cypher脚本?

问题描述 投票:23回答:5

在SQL中:

Delete From Person Where ID = 1;

在Cypher中,按ID删除节点的脚本是什么?

(已编辑:ID = Neo4j的内部节点ID)

neo4j nosql cypher graph-databases
5个回答
40
投票

假设你指的是Neo4j的内部节点id:

MATCH (p:Person) where ID(p)=1
OPTIONAL MATCH (p)-[r]-() //drops p's relations
DELETE r,p

如果您在节点上引用自己的属性“id”:

 MATCH (p:Person {id:1})
 OPTIONAL MATCH (p)-[r]-() //drops p's relations
 DELETE r,p

19
投票

对于id为“xx”的节点,最干净的扫描是

MATCH(n)其中id(n)= xx DETACH DELETE n

(Qazxswpoi)



1
投票

老问题并回答,但要在有关系时删除节点,请使用Start n=node(1) Delete n;

DETACH

或者你得到这个:

MATCH (n) where ID(n)=<your_id> 
DETACH DELETE n

这就像SQL的Neo.ClientError.Schema.ConstraintValidationFailed: Cannot delete node<21>, because it still has relationships. To delete this node, you must first delete its relationships.


0
投票

按照@ saad-khan提供的链接,这是获取节点和关系ID的示例。下面的代码显示了ID,因此您可以确保删除与给定ID相关的所有内容。

CASCADE

Ps。:“:HAS”是关系的一个例子。

© www.soinside.com 2019 - 2024. All rights reserved.