Graph Management
This chapter describes the javascript interface for creating and modifying named graphs. In order to create a non empty graph the functionality to create edge definitions has to be introduced first:
Edge Definitions
An edge definition is always a directed relation of a graph. Each graph can have arbitrary many relations defined within the edge definitions array.
Initialize the list
Create a list of edge definitions to construct a graph.
graph_module._edgeDefinitions(relation1, relation2, ..., relationN)
The list of edge definitions of a graph can be managed by the graph module itself. This function is the entry point for the management and will return the correct list.
Parameters
- relationX (optional) An object representing a definition of one relation in the graph
Examples
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> directed_relation = graph_module._relation("lives_in", "user", "city");
{
"collection" : "lives_in",
"from" : [
"user"
],
"to" : [
"city"
]
}
arangosh> undirected_relation = graph_module._relation("knows", "user", "user");
{
"collection" : "knows",
"from" : [
"user"
],
"to" : [
"user"
]
}
arangosh> edgedefinitions = graph_module._edgeDefinitions(directed_relation, undirected_relation);
[
{
"collection" : "lives_in",
"from" : [
"user"
],
"to" : [
"city"
]
},
{
"collection" : "knows",
"from" : [
"user"
],
"to" : [
"user"
]
}
]
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> directed_relation = graph_module._relation("lives_in", "user", "city");
arangosh> undirected_relation = graph_module._relation("knows", "user", "user");
arangosh> edgedefinitions = graph_module._edgeDefinitions(directed_relation, undirected_relation);
Extend the list
Extend the list of edge definitions to construct a graph.
graph_module._extendEdgeDefinitions(edgeDefinitions, relation1, relation2, ..., relationN)
In order to add more edge definitions to the graph before creating this function can be used to add more definitions to the initial list.
Parameters
- edgeDefinitions (required) A list of relation definition objects.
- relationX (required) An object representing a definition of one relation in the graph
Examples
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> directed_relation = graph_module._relation("lives_in", "user", "city");
{
"collection" : "lives_in",
"from" : [
"user"
],
"to" : [
"city"
]
}
arangosh> undirected_relation = graph_module._relation("knows", "user", "user");
{
"collection" : "knows",
"from" : [
"user"
],
"to" : [
"user"
]
}
arangosh> edgedefinitions = graph_module._edgeDefinitions(directed_relation);
[
{
"collection" : "lives_in",
"from" : [
"user"
],
"to" : [
"city"
]
}
]
arangosh> edgedefinitions = graph_module._extendEdgeDefinitions(undirected_relation);
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> directed_relation = graph_module._relation("lives_in", "user", "city");
arangosh> undirected_relation = graph_module._relation("knows", "user", "user");
arangosh> edgedefinitions = graph_module._edgeDefinitions(directed_relation);
arangosh> edgedefinitions = graph_module._extendEdgeDefinitions(undirected_relation);
Relation
Define a directed relation.
graph_module._relation(relationName, fromVertexCollections, toVertexCollections)
The relationName defines the name of this relation and references to the underlying edge collection. The fromVertexCollections is an Array of document collections holding the start vertices. The toVertexCollections is an Array of document collections holding the target vertices. Relations are only allowed in the direction from any collection in fromVertexCollections to any collection in toVertexCollections.
Parameters
- relationName (required) The name of the edge collection where the edges should be stored. Will be created if it does not yet exist.
- fromVertexCollections (required) One or a list of collection names. Source vertices for the edges have to be stored in these collections. Collections will be created if they do not exist.
- toVertexCollections (required) One or a list of collection names. Target vertices for the edges have to be stored in these collections. Collections will be created if they do not exist.
Examples
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> graph_module._relation("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"]);
{
"collection" : "has_bought",
"from" : [
"Customer",
"Company"
],
"to" : [
"Groceries",
"Electronics"
]
}
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> graph_module._relation("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"]);
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> graph_module._relation("has_bought", "Customer", "Product");
{
"collection" : "has_bought",
"from" : [
"Customer"
],
"to" : [
"Product"
]
}
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> graph_module._relation("has_bought", "Customer", "Product");
Create a graph
After having introduced edge definitions a graph can be created.
Create a graph
graph_module._create(graphName, edgeDefinitions, orphanCollections)
The creation of a graph requires the name of the graph and a definition of its edges.
For every type of edge definition a convenience method exists that can be used to create a graph. Optionally a list of vertex collections can be added, which are not used in any edge definition. These collections are referred to as orphan collections within this chapter. All collections used within the creation process are created if they do not exist.
Parameters
- graphName (required) Unique identifier of the graph
- edgeDefinitions (optional) List of relation definition objects
- orphanCollections (optional) List of additional vertex collection names
Examples
Create an empty graph, edge definitions can be added at runtime:
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> graph = graph_module._create("myGraph");
{[Graph]
}
Create a graph using an edge collection edges
and a single vertex collection vertices
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> var edgeDefinitions = [ { collection: "edges", "from": [ "vertices" ], "to" : [ "vertices" ] } ];
arangosh> graph = graph_module._create("myGraph", edgeDefinitions);
{[Graph]
"edges" : [ArangoCollection 15599, "edges" (type edge, status loaded)],
"vertices" : [ArangoCollection 15597, "vertices" (type document, status loaded)]
}
Create a graph with edge definitions and orphan collections:
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> graph = graph_module._create("myGraph",
........> [graph_module._relation("myRelation", ["male", "female"], ["male", "female"])], ["sessions"]);
{[Graph]
"myRelation" : [ArangoCollection 15490, "myRelation" (type edge, status loaded)],
"female" : [ArangoCollection 15488, "female" (type document, status loaded)],
"male" : [ArangoCollection 15486, "male" (type document, status loaded)],
"sessions" : [ArangoCollection 15492, "sessions" (type document, status loaded)]
}
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> graph = graph_module._create("myGraph",
........> [graph_module._relation("myRelation", ["male", "female"], ["male", "female"])], ["sessions"]);
Complete Example to create a graph
Example Call:
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> var edgeDefinitions = graph_module._edgeDefinitions();
arangosh> graph_module._extendEdgeDefinitions(edgeDefinitions, graph_module._relation("friend_of", "Customer", "Customer"));
arangosh> graph_module._extendEdgeDefinitions(
........> edgeDefinitions, graph_module._relation(
........> "has_bought", ["Customer", "Company"], ["Groceries", "Electronics"]));
arangosh> graph_module._create("myStore", edgeDefinitions);
{[Graph]
"friend_of" : [ArangoCollection 20166, "friend_of" (type edge, status loaded)],
"Customer" : [ArangoCollection 20164, "Customer" (type document, status loaded)],
"has_bought" : [ArangoCollection 20174, "has_bought" (type edge, status loaded)],
"Company" : [ArangoCollection 20168, "Company" (type document, status loaded)],
"Electronics" : [ArangoCollection 20172, "Electronics" (type document, status loaded)],
"Groceries" : [ArangoCollection 20170, "Groceries" (type document, status loaded)]
}
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> var edgeDefinitions = graph_module._edgeDefinitions();
arangosh> graph_module._extendEdgeDefinitions(edgeDefinitions, graph_module._relation("friend_of", "Customer", "Customer"));
arangosh> graph_module._extendEdgeDefinitions(
........> edgeDefinitions, graph_module._relation(
........> "has_bought", ["Customer", "Company"], ["Groceries", "Electronics"]));
arangosh> graph_module._create("myStore", edgeDefinitions);
alternative call:
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> var edgeDefinitions = graph_module._edgeDefinitions(
........> graph_module._relation("friend_of", ["Customer"], ["Customer"]), graph_module._relation(
........> "has_bought", ["Customer", "Company"], ["Groceries", "Electronics"]));
arangosh> graph_module._create("myStore", edgeDefinitions);
{[Graph]
"friend_of" : [ArangoCollection 20193, "friend_of" (type edge, status loaded)],
"Customer" : [ArangoCollection 20191, "Customer" (type document, status loaded)],
"has_bought" : [ArangoCollection 20201, "has_bought" (type edge, status loaded)],
"Company" : [ArangoCollection 20195, "Company" (type document, status loaded)],
"Electronics" : [ArangoCollection 20197, "Electronics" (type document, status loaded)],
"Groceries" : [ArangoCollection 20199, "Groceries" (type document, status loaded)]
}
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> var edgeDefinitions = graph_module._edgeDefinitions(
........> graph_module._relation("friend_of", ["Customer"], ["Customer"]), graph_module._relation(
........> "has_bought", ["Customer", "Company"], ["Groceries", "Electronics"]));
arangosh> graph_module._create("myStore", edgeDefinitions);
List available graphs
List all graphs.
graph_module._list()
Lists all graph names stored in this database.
Examples
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> graph_module._list();
[ ]
Load a graph
Get a graph
graph_module._graph(graphName)
A graph can be retrieved by its name.
Parameters
- graphName (required) Unique identifier of the graph
Examples
Get a graph:
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> graph = graph_module._graph("social");
{[Graph]
"relation" : [ArangoCollection 16073, "relation" (type edge, status loaded)],
"female" : [ArangoCollection 16069, "female" (type document, status loaded)],
"male" : [ArangoCollection 16071, "male" (type document, status loaded)]
}
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> graph = graph_module._graph("social");
Remove a graph
Remove a graph
graph_module._drop(graphName, dropCollections)
A graph can be dropped by its name. This can drop all collections contained in the graph as long as they are not used within other graphs. To drop the collections only belonging to this graph, the optional parameter drop-collections has to be set to true.
Parameters
- graphName (required) Unique identifier of the graph
- dropCollections (optional) Define if collections should be dropped (default: false)
Examples
Drop a graph and keep collections:
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> graph_module._drop("social");
true
arangosh> db._collection("female");
[ArangoCollection 15664, "female" (type document, status loaded)]
arangosh> db._collection("male");
[ArangoCollection 15666, "male" (type document, status loaded)]
arangosh> db._collection("relation");
[ArangoCollection 15668, "relation" (type edge, status loaded)]
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> graph_module._drop("social", true);
true
arangosh> db._collection("female");
null
arangosh> db._collection("male");
null
arangosh> db._collection("relation");
null
Modify a graph definition during runtime
After you have created an graph its definition is not immutable. You can still add, delete or modify edge definitions and vertex collections.
Extend the edge definitions
Add another edge definition to the graph
graph._extendEdgeDefinitions(edgeDefinition)
Extends the edge definitions of a graph. If an orphan collection is used in this edge definition, it will be removed from the orphanage. If the edge collection of the edge definition to add is already used in the graph or used in a different graph with different from and/or to collections an error is thrown.
Parameters
- edgeDefinition (required) The relation definition to extend the graph
Examples
arangosh> var graph_module = require("@arangodb/general-graph")
arangosh> var ed1 = graph_module._relation("myEC1", ["myVC1"], ["myVC2"]);
arangosh> var ed2 = graph_module._relation("myEC2", ["myVC1"], ["myVC3"]);
arangosh> var graph = graph_module._create("myGraph", [ed1]);
arangosh> graph._extendEdgeDefinitions(ed2);
Modify an edge definition
Modify an relation definition
graph_module._editEdgeDefinition(edgeDefinition)
Edits one relation definition of a graph. The edge definition used as argument will replace the existing edge definition of the graph which has the same collection. Vertex Collections of the replaced edge definition that are not used in the new definition will transform to an orphan. Orphans that are used in this new edge definition will be deleted from the list of orphans. Other graphs with the same edge definition will be modified, too.
Parameters
- edgeDefinition (required) The edge definition to replace the existing edge definition with the same attribute collection.
Examples
arangosh> var graph_module = require("@arangodb/general-graph")
arangosh> var original = graph_module._relation("myEC1", ["myVC1"], ["myVC2"]);
arangosh> var modified = graph_module._relation("myEC1", ["myVC2"], ["myVC3"]);
arangosh> var graph = graph_module._create("myGraph", [original]);
arangosh> graph._editEdgeDefinitions(modified);
Delete an edge definition
Delete one relation definition
graph_module._deleteEdgeDefinition(edgeCollectionName, dropCollection)
Deletes a relation definition defined by the edge collection of a graph. If the collections defined in the edge definition (collection, from, to) are not used in another edge definition of the graph, they will be moved to the orphanage.
Parameters
- edgeCollectionName (required) Name of edge collection in the relation definition.
- dropCollection (optional) Define if the edge collection should be dropped. Default false.
Examples
Remove an edge definition but keep the edge collection:
arangosh> var graph_module = require("@arangodb/general-graph")
arangosh> var ed1 = graph_module._relation("myEC1", ["myVC1"], ["myVC2"]);
arangosh> var ed2 = graph_module._relation("myEC2", ["myVC1"], ["myVC3"]);
arangosh> var graph = graph_module._create("myGraph", [ed1, ed2]);
arangosh> graph._deleteEdgeDefinition("myEC1");
arangosh> db._collection("myEC1");
[ArangoCollection 19961, "myEC1" (type edge, status loaded)]
Remove an edge definition and drop the edge collection:
arangosh> var graph_module = require("@arangodb/general-graph")
arangosh> var ed1 = graph_module._relation("myEC1", ["myVC1"], ["myVC2"]);
arangosh> var ed2 = graph_module._relation("myEC2", ["myVC1"], ["myVC3"]);
arangosh> var graph = graph_module._create("myGraph", [ed1, ed2]);
arangosh> graph._deleteEdgeDefinition("myEC1", true);
arangosh> db._collection("myEC1");
null
Extend vertex Collections
Each graph can have an arbitrary amount of vertex collections, which are not part of any edge definition of the graph. These collections are called orphan collections. If the graph is extended with an edge definition using one of the orphans, it will be removed from the set of orphan collection automatically.
Add a vertex collection
Add a vertex collection to the graph
graph._addVertexCollection(vertexCollectionName, createCollection)
Adds a vertex collection to the set of orphan collections of the graph. If the collection does not exist, it will be created. If it is already used by any edge definition of the graph, an error will be thrown.
Parameters
- vertexCollectionName (required) Name of vertex collection.
- createCollection (optional) If true the collection will be created if it does not exist. Default: true.
Examples
arangosh> var graph_module = require("@arangodb/general-graph");
arangosh> var ed1 = graph_module._relation("myEC1", ["myVC1"], ["myVC2"]);
arangosh> var graph = graph_module._create("myGraph", [ed1]);
arangosh> graph._addVertexCollection("myVC3", true);
Get the orphaned collections
Get all orphan collections
graph._orphanCollections()
Returns all vertex collections of the graph that are not used in any edge definition.
Examples
arangosh> var graph_module = require("@arangodb/general-graph")
arangosh> var ed1 = graph_module._relation("myEC1", ["myVC1"], ["myVC2"]);
arangosh> var graph = graph_module._create("myGraph", [ed1]);
arangosh> graph._addVertexCollection("myVC3", true);
arangosh> graph._orphanCollections();
[
"myVC3"
]
Remove a vertex collection
Remove a vertex collection from the graph
graph._removeVertexCollection(vertexCollectionName, dropCollection)
Removes a vertex collection from the graph. Only collections not used in any relation definition can be removed. Optionally the collection can be deleted, if it is not used in any other graph.
Parameters
- vertexCollectionName (required) Name of vertex collection.
- dropCollection (optional) If true the collection will be dropped if it is not used in any other graph. Default: false.
Examples
arangosh> var graph_module = require("@arangodb/general-graph")
arangosh> var ed1 = graph_module._relation("myEC1", ["myVC1"], ["myVC2"]);
arangosh> var graph = graph_module._create("myGraph", [ed1]);
arangosh> graph._addVertexCollection("myVC3", true);
arangosh> graph._addVertexCollection("myVC4", true);
arangosh> graph._orphanCollections();
[
"myVC3",
"myVC4"
]
arangosh> graph._removeVertexCollection("myVC3");
arangosh> graph._orphanCollections();
[
"myVC4"
]
arangosh> var graph_module = require("@arangodb/general-graph")
arangosh> var ed1 = graph_module._relation("myEC1", ["myVC1"], ["myVC2"]);
arangosh> var graph = graph_module._create("myGraph", [ed1]);
arangosh> graph._addVertexCollection("myVC3", true);
arangosh> graph._addVertexCollection("myVC4", true);
arangosh> graph._orphanCollections();
arangosh> graph._removeVertexCollection("myVC3");
arangosh> graph._orphanCollections();
Maniuplating Vertices
Save a vertex
Create a new vertex in vertexCollectionName
graph.vertexCollectionName.save(data)
Parameters
- data (required) JSON data of vertex.
Examples
arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
arangosh> var graph = examples.loadGraph("social");
arangosh> graph.male.save({name: "Floyd", _key: "floyd"});
{
"_id" : "male/floyd",
"_key" : "floyd",
"_rev" : "_VTxTZcO---"
}
arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
arangosh> var graph = examples.loadGraph("social");
arangosh> graph.male.save({name: "Floyd", _key: "floyd"});
Replace a vertex
Replaces the data of a vertex in collection vertexCollectionName
graph.vertexCollectionName.replace(vertexId, data, options)
Parameters
- vertexId (required) _id attribute of the vertex
- data (required) JSON data of vertex.
- options (optional) See collection documentation
Examples
arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
arangosh> var graph = examples.loadGraph("social");
arangosh> graph.male.save({neym: "Jon", _key: "john"});
{
"_id" : "male/john",
"_key" : "john",
"_rev" : "_VTxTZWq--_"
}
arangosh> graph.male.replace("male/john", {name: "John"});
{
"_id" : "male/john",
"_key" : "john",
"_rev" : "_VTxTZWq--A",
"_oldRev" : "_VTxTZWq--_"
}
arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
arangosh> var graph = examples.loadGraph("social");
arangosh> graph.male.save({neym: "Jon", _key: "john"});
arangosh> graph.male.replace("male/john", {name: "John"});
Update a vertex
Updates the data of a vertex in collection vertexCollectionName
graph.vertexCollectionName.update(vertexId, data, options)
Parameters
- vertexId (required) _id attribute of the vertex
- data (required) JSON data of vertex.
- options (optional) See collection documentation
Examples
arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
arangosh> var graph = examples.loadGraph("social");
arangosh> graph.female.save({name: "Lynda", _key: "linda"});
{
"_id" : "female/linda",
"_key" : "linda",
"_rev" : "_VTxTZha---"
}
arangosh> graph.female.update("female/linda", {name: "Linda", _key: "linda"});
{
"_id" : "female/linda",
"_key" : "linda",
"_rev" : "_VTxTZha--_",
"_oldRev" : "_VTxTZha---"
}
arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
arangosh> var graph = examples.loadGraph("social");
arangosh> graph.female.save({name: "Lynda", _key: "linda"});
arangosh> graph.female.update("female/linda", {name: "Linda", _key: "linda"});
Remove a vertex
Removes a vertex in collection vertexCollectionName
graph.vertexCollectionName.remove(vertexId, options)
Additionally removes all ingoing and outgoing edges of the vertex recursively (see edge remove).
Parameters
- vertexId (required) _id attribute of the vertex
- options (optional) See collection documentation
Examples
arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
arangosh> var graph = examples.loadGraph("social");
arangosh> graph.male.save({name: "Kermit", _key: "kermit"});
{
"_id" : "male/kermit",
"_key" : "kermit",
"_rev" : "_VTxTZQK--A"
}
arangosh> db._exists("male/kermit")
true
arangosh> graph.male.remove("male/kermit")
true
arangosh> db._exists("male/kermit")
false
arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
arangosh> var graph = examples.loadGraph("social");
arangosh> graph.male.save({name: "Kermit", _key: "kermit"});
arangosh> db._exists("male/kermit")
arangosh> graph.male.remove("male/kermit")
arangosh> db._exists("male/kermit")
Manipulating Edges
Save a new edge
Creates an edge from vertex from to vertex to in collection edgeCollectionName
graph.edgeCollectionName.save(from, to, data, options)
Parameters
- from (required) _id attribute of the source vertex
- to (required) _id attribute of the target vertex
- data (required) JSON data of the edge
- options (optional) See collection documentation
Examples
arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
arangosh> var graph = examples.loadGraph("social");
arangosh> graph.relation.save("male/bob", "female/alice", {type: "married", _key: "bobAndAlice"});
{
"_id" : "relation/bobAndAlice",
"_key" : "bobAndAlice",
"_rev" : "_VTxTQ2u---"
}
arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
arangosh> var graph = examples.loadGraph("social");
arangosh> graph.relation.save("male/bob", "female/alice", {type: "married", _key: "bobAndAlice"});
If the collections of from and to are not defined in an edge definition of the graph, the edge will not be stored.
arangosh> var examples = require("@arangodb/graph-examples/example-graph.js"); arangosh> var graph = examples.loadGraph("social"); arangosh> graph.relation.save( ........> "relation/aliceAndBob", ........> "female/alice", ........> {type: "married", _key: "bobAndAlice"}); [ArangoError 1906: invalid edge between relation/aliceAndBob and female/alice. Doesn't conform to any edge definition]
Replace an edge
Replaces the data of an edge in collection edgeCollectionName. Note that _from
and _to
are mandatory.
graph.edgeCollectionName.replace(edgeId, data, options)
Parameters
- edgeId (required) _id attribute of the edge
- data (required) JSON data of the edge
- options (optional) See collection documentation
Examples
arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
arangosh> var graph = examples.loadGraph("social");
arangosh> graph.relation.save("female/alice", "female/diana", {typo: "nose", _key: "aliceAndDiana"});
{
"_id" : "relation/aliceAndDiana",
"_key" : "aliceAndDiana",
"_rev" : "_VTxTQwy--B"
}
arangosh> graph.relation.replace("relation/aliceAndDiana", {type: "knows", _from: "female/alice", _to: "female/diana"});
{
"_id" : "relation/aliceAndDiana",
"_key" : "aliceAndDiana",
"_rev" : "_VTxTQw2---",
"_oldRev" : "_VTxTQwy--B"
}
arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
arangosh> var graph = examples.loadGraph("social");
arangosh> graph.relation.save("female/alice", "female/diana", {typo: "nose", _key: "aliceAndDiana"});
arangosh> graph.relation.replace("relation/aliceAndDiana", {type: "knows", _from: "female/alice", _to: "female/diana"});
Update an edge
Updates the data of an edge in collection edgeCollectionName
graph.edgeCollectionName.update(edgeId, data, options)
Parameters
- edgeId (required) _id attribute of the edge
- data (required) JSON data of the edge
- options (optional) See collection documentation
Examples
arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
arangosh> var graph = examples.loadGraph("social");
arangosh> graph.relation.save("female/alice", "female/diana", {type: "knows", _key: "aliceAndDiana"});
{
"_id" : "relation/aliceAndDiana",
"_key" : "aliceAndDiana",
"_rev" : "_VTxTRBm--C"
}
arangosh> graph.relation.update("relation/aliceAndDiana", {type: "quarreled", _key: "aliceAndDiana"});
{
"_id" : "relation/aliceAndDiana",
"_key" : "aliceAndDiana",
"_rev" : "_VTxTRBq---",
"_oldRev" : "_VTxTRBm--C"
}
arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
arangosh> var graph = examples.loadGraph("social");
arangosh> graph.relation.save("female/alice", "female/diana", {type: "knows", _key: "aliceAndDiana"});
arangosh> graph.relation.update("relation/aliceAndDiana", {type: "quarreled", _key: "aliceAndDiana"});
Remove an edge
Removes an edge in collection edgeCollectionName
graph.edgeCollectionName.remove(edgeId, options)
If this edge is used as a vertex by another edge, the other edge will be removed (recursively).
Parameters
- edgeId (required) _id attribute of the edge
- options (optional) See collection documentation
Examples
arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
arangosh> var graph = examples.loadGraph("social");
arangosh> graph.relation.save("female/alice", "female/diana", {_key: "aliceAndDiana"});
{
"_id" : "relation/aliceAndDiana",
"_key" : "aliceAndDiana",
"_rev" : "_VTxTQpq---"
}
arangosh> db._exists("relation/aliceAndDiana")
true
arangosh> graph.relation.remove("relation/aliceAndDiana")
true
arangosh> db._exists("relation/aliceAndDiana")
false
arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
arangosh> var graph = examples.loadGraph("social");
arangosh> graph.relation.save("female/alice", "female/diana", {_key: "aliceAndDiana"});
arangosh> db._exists("relation/aliceAndDiana")
arangosh> graph.relation.remove("relation/aliceAndDiana")
arangosh> db._exists("relation/aliceAndDiana")
Connect edges
Get all connecting edges between 2 groups of vertices defined by the examples
graph._getConnectingEdges(vertexExample, vertexExample2, options)
The function accepts an id, an example, a list of examples or even an empty example as parameter for vertexExample.
Parameters
- vertexExample1 (optional) See Definition of examples
- vertexExample2 (optional) See Definition of examples
- options (optional) An object defining further options. Can have the following values:
- edgeExamples: Filter the edges, see Definition of examples
- edgeCollectionRestriction : One or a list of edge-collection names that should be considered to be on the path.
- vertex1CollectionRestriction : One or a list of vertex-collection names that should be considered on the intermediate vertex steps.
- vertex2CollectionRestriction : One or a list of vertex-collection names that should be considered on the intermediate vertex steps.
Examples
A route planner example, all connecting edges between capitals.
arangosh> var examples = require("@arangodb/graph-examples/example-graph.js");
arangosh> var graph = examples.loadGraph("routeplanner");
arangosh> graph._getConnectingEdges({isCapital : true}, {isCapital : true});
[ ]