ArangoDb使用属性获取边

wsewodh2  于 2022-12-09  发布在  Go
关注(0)|答案(1)|浏览(118)

我正在使用ArangoDb最新版本,我有问题。我有两个集合:
Country(国家/地区)(这是文档集合)和Distance(距离)(这是具有如下键的边集合:_自、_至、距离)。
我如何通过AQL获得有关Country.Continent = 'Europe'所在国家/地区的所有信息,以及它们与边缘收集之间的距离?
SQL将如下所示:
Select * from Country c, Distance d where c.Continent = 'Europe'
谢谢您的支持。

rn0zuynd

rn0zuynd1#

我最近一直在做一个项目,并开始使用ArangoDB,所以希望我能对你有所帮助。
我从Arango和AQL文档的以下链接中获得了一些灵感:

请看下面我的AQL查询,并让我知道如果这有帮助。您可以替换过滤器上的“欧洲”部分的@大陆,这将允许您动态指定它,如果需要的话。

FOR country IN Country
  FILTER country.Continent == 'Europe'
  FOR vertex, edge, path
  IN OUTBOUND country Distance
  RETURN path

我刚刚创建了一些测试集合,用两条边将国家连接在一起。我已经在'FOR'部分包含了查询的顶点、边和路径,所以欢迎您在最后使用'RETURN'部分替换顶点或边,看看会产生什么结果。

[
  {
    "edges": [
      {
        "_key": "67168",
        "_id": "Distance/67168",
        "_from": "Country/67057",
        "_to": "Country/67094",
        "_rev": "_aecXk7---_",
        "Distance": 5
      }
    ],
    "vertices": [
      {
        "_key": "67057",
        "_id": "Country/67057",
        "_rev": "_aecWJ0q--_",
        "countryName": "UK",
        "Continent": "Europe"
      },
      {
        "_key": "67094",
        "_id": "Country/67094",
        "_rev": "_aecWZhi--_",
        "countryName": "Italy",
        "Continent": "Europe"
      }
    ]
  },
  {
    "edges": [
      {
        "_key": "67222",
        "_id": "Distance/67222",
        "_from": "Country/67057",
        "_to": "Country/67113",
        "_rev": "_aecYB9---_",
        "Distance": 10
      }
    ],
    "vertices": [
      {
        "_key": "67057",
        "_id": "Country/67057",
        "_rev": "_aecWJ0q--_",
        "countryName": "UK",
        "Continent": "Europe"
      },
      {
        "_key": "67113",
        "_id": "Country/67113",
        "_rev": "_aecWmEy--_",
        "countryName": "Spain",
        "Continent": "Europe"
      }
    ]
  }
]

例如,如果用“RETURN edge”替换“RETURN path”零件,则只需检索边(如果这就是所需的全部内容),如下所示:

[
  {
    "_key": "67168",
    "_id": "Distance/67168",
    "_from": "Country/67057",
    "_to": "Country/67094",
    "_rev": "_aecXk7---_",
    "Distance": 5
  },
  {
    "_key": "67222",
    "_id": "Distance/67222",
    "_from": "Country/67057",
    "_to": "Country/67113",
    "_rev": "_aecYB9---_",
    "Distance": 10
  }
]

相关问题