SatelliteGraph Management

This chapter describes the satellite-graph module, the JavaScript API to create and modify your SatelliteGraphs in ArangoDB.

To generally understand the concept of the graph modules please see General Graph Management first. In the following only the overloaded functionality is described. Everything else works alike in both modules.

Create a Graph

In contrast to General Graphs and SmartGraphs, you do not need to take care of the sharding and replication properties. The properties distributeShardsLike, replicationFactor and numberOfShards will be set automatically (also see prototype collection).

The format of the relations is identical.

  1. var graph_module = require("@arangodb/satellite-graph");
  2. graph_module._create(graphName, edgeDefinitions, orphanCollections);
  • graphName (string): Unique identifier of the graph
  • edgeDefinitions (array): List of relation definition objects, may be empty
  • orphanCollections (array): List of additional vertex collection names, may be empty

Both edgeDefinitions and orphanCollections are optional. You can also add collections later, after the SatelliteGraph creation took place.

The edgeDefinitions can be created using the convenience method _relation() known from the general-graph module, which is also available here.

orphanCollections again is just a list of additional vertex collections which are not yet connected via edges but should follow the same sharding to be connected later on.

All collections used within the creation process are newly created or, if already available, checked against the collection properties. The process will fail if one of them already exists, unless they have the correct sharding already. All newly created collections will immediately be dropped again in the failure case.

Examples

Create a graph without relations. Edge definitions can be added later:

  1. arangosh> var satelliteGraphModule = require("@arangodb/satellite-graph");
  2. arangosh> var graph = satelliteGraphModule._create("satelliteGraph");
  3. arangosh> satelliteGraphModule._graph("satelliteGraph");

Show execution results

Hide execution results

  1. {[SatelliteGraph]
  2. }

Create a graph using an edge collection edges and a single vertex collection vertices as relation:

  1. arangosh> var graph_module = require("@arangodb/satellite-graph");
  2. arangosh> var edgeDefinitions = [ graph_module._relation("edges", "vertices", "vertices") ];
  3. arangosh> var graph = graph_module._create("myGraph", edgeDefinitions);
  4. arangosh> graph_module._graph("myGraph");

Show execution results

Hide execution results

  1. {[SatelliteGraph]
  2. "edges" : [ArangoCollection 10146, "edges" (type edge, status loaded)],
  3. "vertices" : [ArangoCollection 10144, "vertices" (type document, status loaded)]
  4. }

Create a graph with edge definitions and orphan collections:

  1. arangosh> var graph_module = require("@arangodb/satellite-graph");
  2. arangosh> var edgeDefinitions = [ graph_module._relation("myRelation", ["male", "female"], ["male", "female"]) ];
  3. arangosh> var graph = graph_module._create("myGraph", edgeDefinitions, ["sessions"]);
  4. arangosh> graph_module._graph("myGraph");

Show execution results

Hide execution results

  1. {[SatelliteGraph]
  2. "myRelation" : [ArangoCollection 10155, "myRelation" (type edge, status loaded)],
  3. "female" : [ArangoCollection 10153, "female" (type document, status loaded)],
  4. "male" : [ArangoCollection 10154, "male" (type document, status loaded)],
  5. "sessions" : [ArangoCollection 10151, "sessions" (type document, status loaded)]
  6. }

Modify a SatelliteGraph definition at runtime

After you have created a SatelliteGraph its definition is not immutable. You can still add or remove relations. This is again identical to General Graphs.

However there is one important difference: You can only add collections that either do not exist, or that have been created with the correct collection properties (either through the graph module or manually).

Remove a vertex collection

Remove a vertex collection from the graph:

graph._removeVertexCollection(vertexCollectionName, dropCollection)

  • vertexCollectionName (string): Name of vertex collection.
  • dropCollection (bool, optional): If true the collection will be dropped if it is not used in any other graph. Default: false.

In most cases this function works identically to the General Graph one. But there is one special case: The first vertex collection added to the graph (either orphan or a vertex collection within a relation) defines the sharding for all collections within the graph. They have their distributeShardsLike attribute set to the name of the prototype collection This collection cannot be dropped as long as other collections follow its sharding (i.e. they need to be dropped first).

Examples

Create a SatelliteGraph and list its orphan collections:

  1. arangosh> var graph_module = require("@arangodb/satellite-graph");
  2. arangosh> var relation = graph_module._relation("edges", "vertices", "vertices");
  3. arangosh> var graph = graph_module._create("myGraph", [relation], ["other"]);
  4. arangosh> graph._orphanCollections();

Show execution results

Hide execution results

  1. [
  2. "other"
  3. ]

Remove the orphan collection from the SatelliteGraph and drop the collection:

  1. arangosh> graph._removeVertexCollection("other", true);
  2. arangosh> graph_module._graph("myGraph");

Show execution results

Hide execution results

  1. {[SatelliteGraph]
  2. "edges" : [ArangoCollection 10179, "edges" (type edge, status loaded)],
  3. "vertices" : [ArangoCollection 10176, "vertices" (type document, status loaded)]
  4. }

Attempting to remove a non-orphan collection results in an error:

  1. arangosh> graph._removeVertexCollection("vertices");

Show execution results

Hide execution results

  1. [ArangoError 1928: collection is not in list of orphan collections]

You cannot drop the prototype collection (vertices) as long as it defines the sharding for other collections (edges).

  1. arangosh> var graph_module = require("@arangodb/satellite-graph");
  2. arangosh> var relation = graph_module._relation("edges", "vertices", "vertices");
  3. arangosh> var graph = graph_module._create("myGraph", [relation], []);
  4. arangosh> graph._deleteEdgeDefinition("edges");
  5. arangosh> graph._removeVertexCollection("vertices");
  6. arangosh> db._drop("vertices");

Show execution results

Hide execution results

  1. [ArangoError 1485: Collection 'vertices' must not be dropped while 'edges' has distributeShardsLike set to 'vertices'.]

You may drop the complete graph, but remember to drop collections that you might have removed from the graph beforehand, as they will not be part of the graph definition anymore and thus not be dropped for you. Alternatively, you can truncate the graph if you just want to get rid of the data.

  1. arangosh> var graph_module = require("@arangodb/satellite-graph");
  2. arangosh> var relation = graph_module._relation("edges", "vertices", "vertices");
  3. arangosh> var graph = graph_module._create("myGraph", [relation], []);
  4. arangosh> graph._deleteEdgeDefinition("edges");
  5. arangosh> graph._removeVertexCollection("vertices");
  6. arangosh> graph_module._drop("myGraph", true); // does not drop any collections
  7. arangosh> db._drop("edges"); // drop before sharding-defining 'vertices' collection
  8. arangosh> db._drop("vertices");

Show execution results

Hide execution results

Remove an edge collection

Delete an edge definition from the graph:

graph._deleteEdgeDefinition(edgeCollectionName, dropCollection)

  • edgeCollectionName (string): Name of edge collection.
  • dropCollection (bool, optional): If true the collection will be dropped if it is not used in any other graph. Default: false.

Examples

Create a SatelliteGraph, then delete the edge definition and drop the edge collection:

  1. arangosh> var graph_module = require("@arangodb/satellite-graph");
  2. arangosh> var relation = graph_module._relation("edges", "vertices", "vertices");
  3. arangosh> var graph = graph_module._create("myGraph", [relation], []);
  4. arangosh> graph._deleteEdgeDefinition("edges", true);
  5. arangosh> graph_module._graph("myGraph");

Show execution results

Hide execution results

  1. {[SatelliteGraph]
  2. "vertices" : [ArangoCollection 10203, "vertices" (type document, status loaded)]
  3. }

It is allowed to remove the vertex collection vertices if it is not used in any relation (i.e. after the deletion of the edge definition):

  1. arangosh> graph._deleteEdgeDefinition("edges");
  2. arangosh> graph._removeVertexCollection("vertices");

Show execution results

Hide execution results

Keep in mind that you can not drop the vertices collection until no other collection references it anymore (distributeShardsLike collection property).

Remove a Graph

Remove a SatelliteGraph:

graph_module._drop(graphName, dropCollections)

  • graphName (string): Name of the Graph.
  • dropCollections (bool, optional): Define if collections should be dropped. Default: false.

Examples

Delete a SatelliteGraph and drop its collections:

  1. arangosh> graph_module._drop("myGraph", true);

Show execution results

Hide execution results

Note that removing a graph with the option to drop the collections fails if you removed collections from the graph but did not drop these collections. This is because their distributeShardsLike attribute still references collections that are part of the graph. Dropping collections while others point to them in this way is not allowed. Make sure to drop the referencing collections first.

  1. arangosh> graph._removeVertexCollection("other");
  2. arangosh> graph_module._drop("myGraph", true);

Show execution results

Hide execution results

  1. [ArangoError 1485: Collection 'vertices' must not be dropped while 'other' has distributeShardsLike set to 'vertices'.]