ArangoDB provides documents and edges as a low level way to produce graphs.
Let's say we have set up a graph with some vertices and edges. The graph represents the relationship between the vertices.
v2 is a child of v1
v3 is a child of v2
v4 is a child of v3
v5 is a child of v1
v6 is a child of v5
We want to be able to query:
- The path from v4 to v1
- All descendants of v1
- The children of v1
- All ancestors of v4
- The parents of v4
How to do that in PHP?
The way to do this is by querying ArangoDB with its AQL (ArangoDB Query language).
There are a few commands for working with graphs in AQL. With PHP, we have to create a statement with the query and execute that.
The attached code uses the TRAVERSAL function in order to provide the results to the queries mentioned in the question.
This script sets up a document and an edge collection, fills it with vertices and connecting edges, and finally does the querying in order to provide the results.
It can be executed as is and will print out all the results.