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

查看:17
本文介绍了安全删除 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

另外,有没有办法使用 _ids 或是否有必要使用 _keys 来删除顶点(或边)?我无法让前者工作.

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.

特定于编程语言的驱动程序通常提供包装器这些方法的 REST 接口.

如果您想设计一个为您执行此操作的 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天全站免登陆