4

There's one thing I don't get in ArangoDB:

What's the difference between an edge collection and a graph? In which cases should I choose which?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Mr.Yeah
  • 1,054
  • 2
  • 9
  • 21

2 Answers2

7

Graphs in ArangoDB are built on top of documents and edges.

Edge collections have automatic indexes on _from and _to, allowing efficient retrieval of any connected documents. Because data are still stored in regular (document and edge) collections, you can use these collections in non-graph queries, too.

Graphs add some functionality (i.e. query methods, traversals) on top of the data. You can have multiple of them in ArangoDB. Think of a "graph" being a means of grouping for parts or all of your data, and making them accessible in queries.

stj
  • 9,037
  • 19
  • 33
2

This is an edge:

{
  "_id": "edges/328701573688",
  "_from": "nodes/150194180348",
  "_to": "nodes/328668871224",
  "_rev": "3680146597",
  "_key": "328701573688",
  "type": "includes"
}

This is a document:

{
  "_id": "nodes/328668871224",
  "_rev": "3610088613",
  "_key": "328668871224",
  "name": "Gold-edged Gem",
  "type": "species"
}

As you can see there is no fundamental difference. They are both documents. Edge collections are only useful for when you using Arango for it's graph database capabilities.

As I understand it, the point setting the type of the collection to "edge" tells Arango that it should be ensuring that all documents stored in there minimally have _to and _from attributes so that the document can serve its function as a connector between two other documents.

Once you have a document collection whose documents are connected by a bunch of edge documents in an edge collection... now you have a graph.

mikewilliamson
  • 24,303
  • 17
  • 59
  • 90
  • I disagree with `Edge collections are only useful for [...] graphs`. There are AQL functions to follow edges for instance, but they work directly with the collections, not requiring a general graph. If you want to traverse a highly interconnected graph efficiently and with a certain algorithm, a general graph is required indeed. What to use depends on your data structure and use case. – CodeManX Feb 13 '15 at 18:06
  • I was getting at the fact that it is possible to use Arango as a straight document store, like MongoDB. For people using it that way, the edge collections can be safely ignored. – mikewilliamson Feb 17 '15 at 18:09
  • Edge collections are documents too :) The only difference is that `_to` and `_from` attributes are present and have indices on them. – CodeManX Feb 17 '15 at 22:14