2
votes

I'm working in arangosh (the ArangoDB Shell) trying to put together some graph analyses (which I'll move over to Foxx later, if I can get this working).

I have two collections. A collection of vertices we'll call People, and an edge collection, Relationships.

Following the manual I can create a graph based on People:

var graph_module = require("@arangodb/general-graph");
var graph = graph_module._create("population");

graph._addVertexCollection("People");

But I know that People does not contain the information necessary to connect the vertices in this graph. If anything, I'd rather simply create the graph from the edge collection Relationships since, by definition, all docs in edge collections have the _to and _from fields, from which the graph can be fully specified.

I find the next pages of the manual to be absolutely baffling (my apologies to the authors) and would appreciate any guidance on how to either directly create a graph from an edge collection, or incorporate information from an edge collection into an existing graph.

2

2 Answers

4
votes

So it looks like you want to create a graph with no defined vertex collection, but with an edge collection only. As far as I'm aware of, you must have some sort of vertex collection from which edges may emanate from or go to. But you do not need to explicitly include this vertex collection into your graph. According to the 2.8 docs which admittedly doesn't exactly detail everything, you can create a graph with just edge collections:

arangosh> var graph_module = require("org/arangodb/general-graph");
arangosh> var edgeDefinitions = [ { collection: "edges", "from": [ "vertices" ], "to" : [ "vertices" ] } ];
arangosh> graph = graph_module._create("myGraph", edgeDefinitions);
[ Graph myGraph EdgeDefinitions: [ 
  "edges: [vertices] -> [vertices]" 
] VertexCollections: [ ] ]

Note that the collection "vertices" must exist. You do not necessarily need for the nodes that are referenced in the "edges" collection to exist. But if you want to do anything like a traversal, the nodes must exist in the "vertices" collection, otherwise you'll get "null" as a response for those traversals.

(Pretty sure this answer is applicable to 3.0 as well, but I've mainly been using 2.8 and have yet to upgrade.)

1
votes

The following remarks have been verified using ArangoDB 3.2.

In brief, ArangoDB supports meta-graphs. That is, it is possible to have graphs whose "nodes" are objects in an Edge collection.

Indeed, such graphs are quite ordinary.

For example, suppose we have a Graph, "knows_graph", relating Person to Person, and that the edges of the graph are in the "who_knows_who" Edge collection.

We can create an additional graph, say "causation_graph", relating the "who_knows_who" edges. For example, maybe "Alice knows Bob" resulted in Bob getting to know Charles:

 knows(_from: Alice, _to: Bob) => knows(_from: Bob, _to: Charles)

Let's suppose we gave the name "caused" to the Edge collection in the "causation_graph". Then we can say that in the normal course of things, we started with a Document collection (Person), created an Edge collection (who_knows_who) with Person as the substrate, and then created a "meta-edge" Edge collection whose substrate is the Edge collection, caused.

When using the ArangoDB GUI, one cannot create a Graph without a pre-existing Edge collection, and normally an Edge collection has one or more Document collections as its substrate.

However, it is actually possible to create a self-referential Edge collection: let's call it "selfie". It's likely to tie you up in knots, so be warned. But technically it is possible to have an ArangoDB Graph that is "edges" all the way down.