【问题标题】:ArangoDb get edges with propertiesArangoDb 获得具有属性的边缘
【发布时间】:2020-05-11 12:00:10
【问题描述】:

我正在使用 ArangoDb 最新版本,但我遇到了问题。 我有两个收藏:

国家(这是文档集合)和距离(这是带有键的边缘集合:_from、_to、距离)。

我如何通过 AQL 获取有关 Country.Continent = 'Europe' 的国家/地区的所有信息,以及它们与边缘集合之间的距离?

SQL 应该是这样的:

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

谢谢。

【问题讨论】:

    标签: arangodb aql


    【解决方案1】:

    我最近一直在做一个项目,并开始使用 ArangoDB,希望我能对你有所帮助。

    我从以下 Arango 和 AQL 文档的链接中获得了一些灵感:

    请查看下面我的 AQL 查询,如果有帮助,请告诉我。您可以将 FILTER 上的“欧洲”部分替换为 @Continent,这将允许您在需要时动态指定它。

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

    这对我产生了以下结果。我刚刚创建了一些测试集合,其中有 2 条边将国家连接在一起。我已经在“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"
          }
        ]
      }
    ]
    

    例如,如果您将“RETURN path”部分替换为“RETURN edge”,则只需检索边缘即可,如下所示:

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

    【讨论】:

    • 很好解释。工作正常!谢谢。
    • @BeFine9,这只是一种乐趣。我很高兴它对你有用。
    • @BeFine9,如果对你有帮助,你能接受这个答案吗?
    • 是的,我在几天前(12.05 13:30)这样做了。不是吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-01
    • 2020-12-27
    • 1970-01-01
    相关资源
    最近更新 更多