安全删除ArangoDB中的顶点(使用_ids)? [英] Safe removal of vertexes in ArangoDB (using _ids)?

查看:97
本文介绍了安全删除ArangoDB中的顶点(使用_ids)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AQL在ArangoDB中为顶点和边缘创建一些删除查询,并且我假设将有一种安全"的方式来删除顶点,该顶点也将删除关联的边缘.但是我在文档或其他任何地方都找不到.以下是进行安全删除的最佳方法吗?

I'm creating some removal queries for vertices and edges in ArangoDB using AQL and I assumed there would be a "safe" way to delete vertices that would also remove associated edges. But I can't find any in the documentation or anywhere else. Is the following the best way to do a safe delete?

FOR e IN GRAPH_EDGES('EdgeClass',docId,{direction:'any',maxDepth:1, includeData:false})
    REMOVE e._key FROM EdgeClass

REMOVE docKey IN DocumentClass

还可以使用_id s去除顶点(或边)吗?还是需要使用_key s?我无法让前者上班.

Also, is there a way to remove vertices (or edges) using _ids or is it necessary to use _keys? I couldn't get the former to work.

推荐答案

当前不通过AQL处理删除顶点. 图形管理界面提供了顶点删除功能.

Deleting vertices is currently not handled via AQL. The graph management interface offers vertex deletion functionality.

编程语言特定的驱动程序通常提供包装器如果您想设计一个为您执行此操作的AQL查询,则必须知道某个顶点是否仅在一个图形中使用,以及此删除可能涉及的边集合的数量.您可能想使用更现代的图形遍历.让我们尝试从已知图中删除前夕:

If you want to design an AQL query that does this for you, you'd i.e. have to know whether a vertex is only used in one graph, and the number of edge collections that could be concerned by this deletion. You would probably want to use the more modern graph traversals. Lets try to remove eve from the knows graph:

LET keys = (
  FOR v, e IN 1..1 ANY 'persons/eve' GRAPH 'knows_graph' RETURN e._key)
     LET r = (FOR key IN keys REMOVE key IN knows) REMOVE 'eve' IN persons

因此,我们让遍历为我们提供了夏娃所有边缘的_key .然后,我们从knows边缘集合中删除所有这些边缘.之后,我们将夏娃本人移走.

So, we let the the traversal give us the _key of all edges of Eve. We then remove all these edges from the knows edge collection. After that we remove Eve herself.

但是,您可以轻松地看到您必须针对自己的情况来设计这样的查询.

However, you can easily see that you have to craft such a query specific for your situation.

编辑:这样可以使操作更优雅:

edit: one can do this a little more elegant like this:

LET keys = (FOR v, e IN 1..1 ANY 'persons/eve' GRAPH 'knows_graph'
            REMOVE e._key IN knows)
  REMOVE 'eve' IN persons

这篇关于安全删除ArangoDB中的顶点(使用_ids)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆