ArangoDB v2.8 reached End of Life (EOL) and is no longer supported.

This documentation is outdated. Please see the most recent version here: Try latest

Edges, Identifiers, Handles

This is an introduction to ArangoDB’s interface for edges and how to handle edges from the JavaScript shell arangosh. For other languages see the corresponding language API.

Edges in ArangoDB are special documents. In addition to the internal attributes _key, _id and _rev, they have two attributes _from and _to, which contain document handles, namely the start-point and the end-point of the edge. The values of _from and _to are immutable once saved.

Edge collections are special collections that store edge documents. Edge documents are connection documents that reference other documents. The type of a collection must be specified when a collection is created and cannot be changed afterwards.

To change edge endpoints you would need to remove old document/edge and insert new one. Other fields can be updated as in default collection.

Working with Edges

Insert

edge-collection.insert(from, to, document)
Saves a new edge and returns the document-handle. from and to must be documents or document references.
edge-collection.insert(from, to, document, waitForSync)
The optional waitForSync parameter can be used to force synchronization of the document creation operation to disk even in case that the waitForSync flag had been disabled for the entire collection. Thus, the waitForSync parameter can be used to force synchronization of just specific operations. To use this, set the waitForSync parameter to true. If the waitForSync parameter is not specified or set to false, then the collection’s default waitForSync behavior is applied. The waitForSync parameter cannot be used to disable synchronization for collections that have a default waitForSync value of true.

Examples

arangosh> db._create("vertex");
arangosh> db._createEdgeCollection("relation");
arangosh> v1 = db.vertex.insert({ name : "vertex 1" });
arangosh> v2 = db.vertex.insert({ name : "vertex 2" });
arangosh> e1 = db.relation.insert(v1, v2, { label : "knows" });
arangosh> db._document(e1);
show execution results


Edges

edge-collection.edges(vertex)
The edges operator finds all edges starting from (outbound) or ending in (inbound) vertex.
edge-collection.edges(vertices)
The edges operator finds all edges starting from (outbound) or ending in (inbound) a document from vertices, which must a list of documents or document handles.

arangosh> db._create("vertex");
arangosh> db._createEdgeCollection("relation");
arangosh> myGraph.v1 = db.vertex.insert({ name : "vertex 1" });
arangosh> myGraph.v2 = db.vertex.insert({ name : "vertex 2" });
arangosh> myGraph.e1 = db.relation.insert(myGraph.v1, myGraph.v2, { label : "knows" });
arangosh> db._document(myGraph.e1);
arangosh> db.relation.edges(myGraph.e1._id);
show execution results


InEdges

edge-collection.inEdges(vertex)
The edges operator finds all edges ending in (inbound) vertex.
edge-collection.inEdges(vertices)
The edges operator finds all edges ending in (inbound) a document from vertices, which must a list of documents or document handles.

Examples

arangosh> db._create("vertex");
arangosh> db._createEdgeCollection("relation");
arangosh> myGraph.v1 = db.vertex.insert({ name : "vertex 1" });
arangosh> myGraph.v2 = db.vertex.insert({ name : "vertex 2" });
arangosh> myGraph.e1 = db.relation.insert(myGraph.v1, myGraph.v2, { label : "knows" });
arangosh> db._document(myGraph.e1);
arangosh> db.relation.inEdges(myGraph.v1._id);
arangosh> db.relation.inEdges(myGraph.v2._id);
show execution results


OutEdges

edge-collection.outEdges(vertex)
The edges operator finds all edges starting from (outbound) vertices.
edge-collection.outEdges(vertices)
The edges operator finds all edges starting from (outbound) a document from vertices, which must a list of documents or document handles.

Examples

arangosh> db._create("vertex");
arangosh> db._createEdgeCollection("relation");
arangosh> myGraph.v1 = db.vertex.insert({ name : "vertex 1" });
arangosh> myGraph.v2 = db.vertex.insert({ name : "vertex 2" });
arangosh> myGraph.e1 = db.relation.insert(myGraph.v1, myGraph.v2, { label : "knows" });
arangosh> db._document(myGraph.e1);
arangosh> db.relation.outEdges(myGraph.v1._id);
arangosh> db.relation.outEdges(myGraph.v2._id);
show execution results