Whats the best method to to filter graph edges by type in AQL

给你一囗甜甜゛ 提交于 2019-12-23 13:06:31

问题


I have the following super-simple graph :

What i am trying to do is:

  1. Select all questions where there is a property on the question document called firstQuestion with a value of true.
  2. Select any options that are connected to the question via an outbound edge of type with_options

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}

回答1:


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}


来源:https://stackoverflow.com/questions/35070470/whats-the-best-method-to-to-filter-graph-edges-by-type-in-aql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!