首页 > 解决方案 > Arangodb AQL Query for multiple edge definitions

问题描述

I am new to graph databases and arangodb too. I try to query a graph with different edge definitions and didn't find any example for this. A query to get a result for one edge I found.

FOR p IN person
  FOR vx, ex, px IN ANY p GRAPH "test" FILTER vx.brand == "BMW" RETURN DISTINCT p

For example: I have vertices "person", "car" and "house" and edges "has_car" (person->car) and "lives_in" (person->house). To try out I created three graphs. One for each edge definition and one with both edge definitions.

My question: What is the right way to query:

  1. Persons who have a "BMW" and live in a "Castle"
  2. Persons who live in a "Skyscraper" and don't have a car
  3. Persons who live in a "Skyscraper" and don't have a "BMW"

Thanks.

标签: arangodbaql

解决方案


如果你从头开始呢?这样你就可以检查整个路径

以下是从宝马汽车开始的示例(第一个问题)

for car in Car filter car.brand=="BMW"
  for v,e,p in 0..2 any car._id graph 'test'
    filter p.edges[0]!=null && is_same_collection('has_car', p.edges[0])
    && p.vertices[1]!=null && is_same_collection('Person', p.vertices[1])
    && p.edges[1]!=null && is_same_collection('lives_in', p.edges[1])
    && p.vertices[2]!=null && p.vertices[2].house=="Castle"
  return distinct(p.vertices[1])

推荐阅读