1
votes

I have the following two collections in arangoDB, airports which are the vertices and flights which are the edges.

I would like to create a graph out of them, through the command line. I have found upon the following code, which should do that, but when I click on the graph( that gets successfully created ) in the interface it shows me different graph views. Sometimes with many/different number of nodes and edges and sometimes with one node.

I have no idea why it behaves that way, or if the following code is actually good ?

Any expert in ArangoDB ?

var graph_module = require("@arangodb/general-graph");
var graph = graph_module._create("flightFliesToAirport");
graph;
[ Graph flightFliesToAirport EdgeDefinitions: [ ] VertexCollections: [ ] ]

graph._addVertexCollection("airports");
graph;
[ Graph flightFliesToAirport EdgeDefinitions: ["flights"] VertexCollections: [ 
  "airports", 
] ]

var rel = graph_module._relation("flights" , ["airports"], ["airports"]);
graph._extendEdgeDefinitions(rel);
graph;
[ Graph flightFliesToAirport EdgeDefinitions: [ 
"flights: [airports] -> [airports]"
] VertexCollections: [ ] ]
1

1 Answers

1
votes

The intermediate result actually looks like this I guess (no edge definitions yet)?

graph._addVertexCollection("airports");
graph;
[ Graph flightFliesToAirport EdgeDefinitions: [ ] VertexCollections: [ 
  "airports", 
] ]

The code looks alright and basically answers the question how to create a graph through command line.

Regarding the web interface, please note that each time you open a named graph a random start node is chosen (a single airport). This node and its immediate neighbors are displayed. If it has no edges, then only this one node will show.

You can click on the burger icon on the right-hand side to open the graph viewer properties and specify a start node of your choosing by putting a document ID into the first field (leave the field or hit enter to confirm).

In your case, you can run the following query in the editor:

FOR edge IN flights LIMIT 100 RETURN edge

The query result should default to Graph instead of JSON and display more than a start node and its direct neighborhood. You can increase the limit, but note that it can take a long time to process thousands of nodes and might crash your browser if you return too many edges for the graph viewer to layout and render.