本文介绍了什么是在AQL中按类型过滤图形边缘的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下超简单图形:

I have the following super-simple graph :

我想做的是:

  1. 选择所有在问题文档中具有名为firstQuestion且值为true的属性的问题.
  2. 选择通过类型为with_options的出站边缘连接到问题的所有选项

以下查询有效,但是感觉必须有一种更好的方法来检查边缘类型而不使用字符串操作-特别是我通过将边缘_id值连接到具有边缘类型的键来重新创建边缘_id值的连接操作我想要-这是检查边缘类型的最佳方法吗?

The following query works, however it feels like there must be a better way to inspect the edge type without using string operations - specifically the concatenation operation i use to recreate the edge _id value by joining it to the key with the edge type i want - is this the best way to inspect the type of edge?

FOR question IN questions 
FILTER question.firstQuestion == true
    let options = 
        (FOR v, e IN 1..1 OUTBOUND question._id GRAPH 'mygraph'
        FILTER CONCAT('with_options/', e._key) == e._id
        RETURN v)
RETURN {question: question, options: options}

推荐答案

我们目前正在引入 IS_SAME_COLLECTION 专门用于ArangoDB 2.8.1.在这种情况下, DOCUMENT 函数也值得一提.

We're currently introducing IS_SAME_COLLECTION for that specific purpose with ArangoDB 2.8.1.The DOCUMENT function is also worth to mention in this context.

FOR question IN questions 
  FILTER question.firstQuestion == true
  LET options = (FOR v, e IN 1..1 OUTBOUND question._id GRAPH 'mygraph'
                   FILTER IS_SAME_COLLECTION('with_options', e._id)
                     RETURN v)
  RETURN {question: question, options: options}

但是,在这种特殊情况下,最好的解决方案不是使用命名的图形界面,而是首先指定遍历应关注的边缘集合的列表:

However, the best solution in this special case is not to use the named graph interface, but specify the list of edge collections that should be concerned by the traversal in first place:

FOR question IN questions 
  FILTER question.firstQuestion == true
  LET options = (FOR v, e IN 1..1 OUTBOUND question._id with_options RETURN v)
  RETURN {question: question, options: options}

这篇关于什么是在AQL中按类型过滤图形边缘的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 07:08