简体   繁体   English

ArangoDb 获取具有属性的边

[英]ArangoDb get edges with properties

I am using ArangoDb newest version and I have problem.我正在使用 ArangoDb 最新版本,但我遇到了问题。 I have two collections:我有两个 collections:

Country (and this is document collection) and Distance (this is edge collection with keys like: _from, _to, distance).国家(这是文档集合)和距离(这是带有键的边缘集合:_from、_to、距离)。

How can I get via AQL all information about countries where Country.Continent = 'Europe' with distances between them from edge collection?如何通过 AQL 获取有关Country.Continent = 'Europe'国家/地区的所有信息,以及它们与边缘集合之间的距离?

SQL would be like this: SQL 将是这样的:

Select * from Country c, Distance d where c.Continent = 'Europe'

Thank You.谢谢你。

I have been working on a project recently and started using ArangoDB so hopefully I can be of assistance to you.我最近一直在做一个项目并开始使用 ArangoDB,所以希望我能对你有所帮助。

I took some inspiration for my answer from the below links of the Arango and AQL documentation:我从 Arango 和 AQL 文档的以下链接中获得了一些灵感:

Please see below my AQL query and do let me know if that helped at all.请在下面查看我的 AQL 查询,如果这有帮助,请告诉我。 You can substitute the 'Europe' part on the FILTER for @Continent which will allow you to specify it dynamically, if need be.您可以将 FILTER 上的“欧洲”部分替换为 @Continent,这将允许您在需要时动态指定它。

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

This yields the following result for me.这为我产生了以下结果。 I just created some test collections with 2 edges linking countries together.我刚刚创建了一些测试 collections ,其中 2 个边将国家连接在一起。 I have included the vertex, edge as well as the path of the query in the 'FOR' part, so you are welcome to play around with the 'RETURN' part at the end by substituting the vertex or edge and seeing what results that yields for you.我已经在“FOR”部分中包含了查询的顶点、边和路径,因此欢迎您通过替换顶点或边并查看产生的结果来玩最后的“返回”部分为你。

[
  {
    "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"
      }
    ]
  }
]

For example if you substitute the 'RETURN path' part with 'RETURN edge', you will just retrieve the edges if that is all you need, as per below:例如,如果您将“返回路径”部分替换为“返回边缘”,则只需检索边缘即可,如下所示:

[
  {
    "_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
  }
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM