简体   繁体   English

如何使用Neo4j密码查询删除节点及其连接的节点?

[英]How to delete a node and its connected nodes with Neo4j cypher query?

For example, I want to delete Actor node with id = "005A" and its connected Movie nodes. 例如,我要删除id =“ 005A”的Actor节点及其连接的Movie节点。 The relationship between Actor and Movie node is ACTED_IN . Actor和Movie节点之间的关系是ACTED_IN

I have tried this cypher query: 我已经尝试过以下密码查询:

MATCH (a:Actor {id: "005A"})
OPTIONAL MATCH (a)-[r:ACTED_IN]->(m)
DELETE a, r, m;

but it didn't work, I got TransactionFailureException: Unable to commit transaction error. 但它不起作用,我收到了TransactionFailureException: Unable to commit transaction错误。

Anyone can give a solution? 有人可以提供解决方案吗?

UPDATE: 更新:

I found out that there is relationship from other node ( Agency ) to Actor node which labeled as OWNED . 我发现从其他节点( Agency )到Actor节点之间存在关系,标记为OWNED So the diagram is like this: 因此该图是这样的:

(aa:Agency)-[o:OWNED]->(a:Actor)

[EDITED] [编辑]

You cannot delete a node unless all of its relationships have also been deleted. 除非还删除了所有节点的关系,否则您无法删除该节点。 In your case, it is possible that the a and/or m nodes have relationships other than r . 在您的情况下, a和/或m节点可能具有除r之外的关系。

To get the set of relationship types associated with a and m , you can use the following (I've limited the result to 10 rows, in case a and/or m have a lot of relationships`): 要获取与am关联的a组关系类型,可以使用以下命令(如果a和/或m有很多关联,我将结果限制为10行):

MATCH (a:Actor {id: "005A"})
OPTIONAL MATCH ()-[rx]-(a)
OPTIONAL MATCH (a)-[r:ACTED_IN]->(m)
OPTIONAL MATCH (m)-[ry]-()
RETURN a, r, m, COLLECT(DISTINCT TYPE(rx)), COLLECT(DISTINCT TYPE(ry))
LIMIT 10;

I suspect that your results will show types other than ACTED_IN . 我怀疑您的结果将显示ACTED_IN以外的其他类型。

The following query should delete the actor and all movies s/he acted in: 以下查询应删除该演员和他/她参加过的所有电影:

MATCH (a:Actor {id: "005A"})
OPTIONAL MATCH ()-[rx]-(a)
OPTIONAL MATCH (a)-[r:ACTED_IN]->(m)
OPTIONAL MATCH (m)-[ry]-()
DELETE rx, ry, r, a, m;

Are you sure the id is encoded as a string property ? 您确定id编码为字符串属性吗? I guess the id of the movie database is an integer and thus the id should not be encapsulated in quotes : 我猜电影数据库的ID是一个整数,因此该ID不应封装在引号中:

MATCH (a:Actor {id: 5})
OPTIONAL MATCH (a)-[r:ACTED_IN]->(m)
DELETE a, r, m;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Neo4j密码查询以找出连接的节点 - Neo4j cypher query to find out connected nodes Neo4j Cypher查询查找未连接的节点太慢 - Neo4j Cypher query to find nodes that are not connected too slow Neo4j密码查询以查看给定节点是否已连接 - Neo4j cypher query to see whether given nodes are connected Neo4j Cypher查询,用于查找具有关系的连接节点 - Neo4j Cypher query for finding connected nodes with a relationship Neo4j Cypher Query:查找连接到一个节点且具有 3 个以上其他关系的所有节点 - Neo4j Cypher Query: Finding all nodes, that are connected to a node, that has more than 3 other relationships Neo4j:检索连接到Neo4j Rest中的节点或通过Cypher的所有节点和关系 - Neo4j : Retrieving All Nodes and Relationship connected to a Node in Neo4j Rest OR through Cypher 如何找到Neo4j和Cypher中的一系列连接节点的头部? - How to find the head of a series of connected nodes in Neo4j with Cypher? neo4j密码查询可删除中间节点并将其所有父节点连接到子节点 - neo4j cypher query to delete a middle node and connect all its parent node to child node 如何在Neo4j的Cypher中获取连接到集合中每个其他节点的节点? - How to get in Neo4j's Cypher the nodes that are connected to every other node within a set? 如何从Neo4j Cypher搜索结果中排除连接到特定节点的节点 - How to exclude nodes connected to a specific node from Neo4j Cypher search results
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM