Rm5*_*558 25 neo4j nosql graph-databases cypher
在SQL中:
Delete From Person Where ID = 1;
在Cypher中,按ID删除节点的脚本是什么?
(已编辑:ID = Neo4j的内部节点ID)
Lua*_*nne 42
假设你指的是Neo4j的内部节点id:
MATCH (p:Person) where ID(p)=1
OPTIONAL MATCH (p)-[r]-() //drops p's relations
DELETE r,p
Run Code Online (Sandbox Code Playgroud)
如果您在节点上引用自己的属性"id":
MATCH (p:Person {id:1})
OPTIONAL MATCH (p)-[r]-() //drops p's relations
DELETE r,p
Run Code Online (Sandbox Code Playgroud)
小智 20
对于id为"xx"的节点,最干净的扫描是
MATCH(n)其中id(n)= xx DETACH DELETE n
(https://neo4j.com/docs/developer-manual/current/cypher/#delete-delete-all-nodes-and-relationships)
老问题和答案,但是要在有关系时删除节点,请使用DETACH
MATCH (n) where ID(n)=<your_id>
DETACH DELETE n
Run Code Online (Sandbox Code Playgroud)
否则你会得到这个:
Neo.ClientError.Schema.ConstraintValidationFailed: Cannot delete node<21>, because it still has relationships. To delete this node, you must first delete its relationships.
Run Code Online (Sandbox Code Playgroud)
这就像SQL的CASCADE