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");
[ArangoCollection 519194753, "vertex" (type document, status loaded)]
arangosh> db._createEdgeCollection("relation");
[ArangoCollection 519325825, "relation" (type edge, status loaded)]
arangosh> v1 = db.vertex.insert({ name : "vertex 1" });
{
"_id" : "vertex/519653505",
"_rev" : "519653505",
"_key" : "519653505"
}
arangosh> v2 = db.vertex.insert({ name : "vertex 2" });
{
"_id" : "vertex/519850113",
"_rev" : "519850113",
"_key" : "519850113"
}
arangosh> e1 = db.relation.insert(v1, v2, { label : "knows" });
{
"_id" : "relation/520177793",
"_rev" : "520177793",
"_key" : "520177793"
}
arangosh> db._document(e1);
{
"label" : "knows",
"_id" : "relation/520177793",
"_rev" : "520177793",
"_key" : "520177793",
"_from" : "vertex/519653505",
"_to" : "vertex/519850113"
}
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);
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");
[ArangoCollection 520505473, "vertex" (type document, status loaded)]
arangosh> db._createEdgeCollection("relation");
[ArangoCollection 520636545, "relation" (type edge, status loaded)]
arangosh> myGraph.v1 = db.vertex.insert({ name : "vertex 1" });
{
"_id" : "vertex/520964225",
"_rev" : "520964225",
"_key" : "520964225"
}
arangosh> myGraph.v2 = db.vertex.insert({ name : "vertex 2" });
{
"_id" : "vertex/521160833",
"_rev" : "521160833",
"_key" : "521160833"
}
arangosh> myGraph.e1 = db.relation.insert(myGraph.v1, myGraph.v2, { label : "knows" });
{
"_id" : "relation/521488513",
"_rev" : "521488513",
"_key" : "521488513"
}
arangosh> db._document(myGraph.e1);
{
"label" : "knows",
"_id" : "relation/521488513",
"_rev" : "521488513",
"_key" : "521488513",
"_from" : "vertex/520964225",
"_to" : "vertex/521160833"
}
arangosh> db.relation.edges(myGraph.e1._id);
[ ]
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);
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");
[ArangoCollection 521881729, "vertex" (type document, status loaded)]
arangosh> db._createEdgeCollection("relation");
[ArangoCollection 522012801, "relation" (type edge, status loaded)]
arangosh> myGraph.v1 = db.vertex.insert({ name : "vertex 1" });
{
"_id" : "vertex/522340481",
"_rev" : "522340481",
"_key" : "522340481"
}
arangosh> myGraph.v2 = db.vertex.insert({ name : "vertex 2" });
{
"_id" : "vertex/522537089",
"_rev" : "522537089",
"_key" : "522537089"
}
arangosh> myGraph.e1 = db.relation.insert(myGraph.v1, myGraph.v2, { label : "knows" });
{
"_id" : "relation/522864769",
"_rev" : "522864769",
"_key" : "522864769"
}
arangosh> db._document(myGraph.e1);
{
"label" : "knows",
"_id" : "relation/522864769",
"_rev" : "522864769",
"_key" : "522864769",
"_from" : "vertex/522340481",
"_to" : "vertex/522537089"
}
arangosh> db.relation.inEdges(myGraph.v1._id);
[ ]
arangosh> db.relation.inEdges(myGraph.v2._id);
[
{
"label" : "knows",
"_id" : "relation/522864769",
"_rev" : "522864769",
"_key" : "522864769",
"_from" : "vertex/522340481",
"_to" : "vertex/522537089"
}
]
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);
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");
[ArangoCollection 523323521, "vertex" (type document, status loaded)]
arangosh> db._createEdgeCollection("relation");
[ArangoCollection 523454593, "relation" (type edge, status loaded)]
arangosh> myGraph.v1 = db.vertex.insert({ name : "vertex 1" });
{
"_id" : "vertex/523782273",
"_rev" : "523782273",
"_key" : "523782273"
}
arangosh> myGraph.v2 = db.vertex.insert({ name : "vertex 2" });
{
"_id" : "vertex/523978881",
"_rev" : "523978881",
"_key" : "523978881"
}
arangosh> myGraph.e1 = db.relation.insert(myGraph.v1, myGraph.v2, { label : "knows" });
{
"_id" : "relation/524306561",
"_rev" : "524306561",
"_key" : "524306561"
}
arangosh> db._document(myGraph.e1);
{
"label" : "knows",
"_id" : "relation/524306561",
"_rev" : "524306561",
"_key" : "524306561",
"_from" : "vertex/523782273",
"_to" : "vertex/523978881"
}
arangosh> db.relation.outEdges(myGraph.v1._id);
[
{
"label" : "knows",
"_id" : "relation/524306561",
"_rev" : "524306561",
"_key" : "524306561",
"_from" : "vertex/523782273",
"_to" : "vertex/523978881"
}
]
arangosh> db.relation.outEdges(myGraph.v2._id);
[ ]
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);