Reputation: 25
I am using ArangoDb newest version and I have problem. I have two collections:
Country (and this is document collection) and Distance (this is edge collection with keys like: _from, _to, distance).
How can I get via AQL all information about countries where Country.Continent = 'Europe'
with distances between them from edge collection?
SQL would be like this:
Select * from Country c, Distance d where c.Continent = 'Europe'
Thank You.
Upvotes: 1
Views: 1134
Reputation: 373
I have been working on a project recently and started using ArangoDB so hopefully I can be of assistance to you.
I took some inspiration for my answer from the below links of the Arango and AQL documentation:
Please see below my AQL query and do let me know if that helped at all. You can substitute the 'Europe' part on the FILTER for @Continent which will allow you to specify it dynamically, if need be.
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. 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.
[
{
"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
}
]
Upvotes: 1