我最近一直在做一个项目,并开始使用 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
}
]