1
0
Fork 0
arangodb/Documentation/Books/Users/Traversals
Jan Steemann 9df0c002cd issue #1372: fixed wrong parameter in traversal documentation 2015-06-12 16:08:41 +02:00
..
ExampleData.mdpp Changed README.html to index.html in the documentation 2015-06-09 09:40:12 +02:00
README.mdpp the great rename: array => object, list => array 2014-12-18 22:33:23 +01:00
UsingTraversalObjects.mdpp issue #1372: fixed wrong parameter in traversal documentation 2015-06-12 16:08:41 +02:00

README.mdpp

!CHAPTER Traversals

ArangoDB provides several ways to query graph data. Very simple operations can
be composed with the low-level edge methods *edges*, *inEdges*, and *outEdges* for
[edge collections](../Edges/README.md). For more complex operations,
ArangoDB provides predefined traversal objects.

For any of the following examples, we'll be using the example collections *v* and *e*,
populated with continents, countries and capitals data listed below (see [Example Data](../Traversals/ExampleData.md)).

!SECTION Starting from Scratch

ArangoDB provides the *edges*, *inEdges*, and *outEdges* methods for edge collections.
These methods can be used to quickly determine if a vertex is connected to other vertices,
and which.
This functionality can be exploited to write very simple graph queries in JavaScript.

For example, to determine which edges are linked to the *world* vertex, we can use *inEdges*:

```js
db.e.inEdges('v/world').forEach(function(edge) { 
  require("internal").print(edge._from, "->", edge.type, "->", edge._to); 
});
```

*inEdges* will give us all ingoing edges for the specified vertex *v/world*. The result
is a JavaScript array that we can iterate over and print the results:

```js
v/continent-africa -> is-in -> v/world
v/continent-south-america -> is-in -> v/world
v/continent-asia -> is-in -> v/world
v/continent-australia -> is-in -> v/world
v/continent-europe -> is-in -> v/world
v/continent-north-america -> is-in -> v/world
```

**Note**: *edges*, *inEdges*, and *outEdges* return an array of edges. If we want to retrieve
the linked vertices, we can use each edges' *_from* and *_to* attributes as follows:

```js
db.e.inEdges('v/world').forEach(function(edge) { 
  require("internal").print(db._document(edge._from).name, "->", edge.type, "->", db._document(edge._to).name); 
});
```

We are using the *document* method from the *db* object to retrieve the connected vertices now.

While this may be sufficient for one-level graph operations, writing a traversal by hand
may become too complex for multi-level traversals.