[英]Deleting a neo4j node along with its relationships through java core API
My objective is to delete a node along with all its relationships in a single shot in neo4j graph database. 我的目标是在neo4j图形数据库中一次性删除一个节点及其所有关系。
So far, I have been following this approach, 到目前为止,我一直在遵循这种方法,
- Get all the relationships(BOTH direction) for a node
获取一个节点的所有关系(双向)
- delete the relationships
删除关系
- finally delete the node.
最后删除该节点。
Is this the standard approach or anything else available? 这是标准方法还是其他可用方法? I don't intend to use Cypher query for this.
我不打算为此使用Cypher查询。 I want to achieve this through Java core API itself.
我想通过Java核心API本身实现此目标。
when using java API the described steps are correct: 使用Java API时,所描述的步骤是正确的:
try (Transaction tx = graphDb.beginTx()) {
Node node = // my node to delete
for (Relationship r : node.getRelationships()) {
r.delete();
}
node.delete();
tx.success();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.