Documents and Edge in ArangoDB

63 views
Skip to first unread message

Marcela Guerrero

unread,
Aug 26, 2020, 12:07:28 PM8/26/20
to ArangoDB
Can edges only be used for the graph data model? Or I can use it similarly as if it were a many-to-many relationship in the relational model. 
What happens to many-to-many relationships in ArangoDB in the event that there are more than two involved tables as evidenced in a relational model ?

Kerry Hormann

unread,
Aug 26, 2020, 12:21:43 PM8/26/20
to aran...@googlegroups.com
Edges can only be one-to-one, and are directional (to/from).  But that doesn’t mean you can’t create lots of edges that connect a single node to many others.

The challenge is not in creating the relationships, but in how you query.  Making sure you are not creating loops, or more specifically, loops that leads to loops.  This would increase traversal complexity by orders of magnitude, rendering even simple queries impossible.

There are options to ensure a path is only traversed once, but those are really for handling special cases, not every-day queries.  It is MUCH more important to model your data appropriately.

Having lots of edges is not a problem - a poor data model is (and missing indexes, too).

— Kerry

On Wed, Aug 26, 2020 at 9:07 AM Marcela Guerrero <marcelagu...@gmail.com> wrote:
Can edges only be used for the graph data model? Or I can use it similarly as if it were a many-to-many relationship in the relational model. 
What happens to many-to-many relationships in ArangoDB in the event that there are more than two involved tables as evidenced in a relational model ?









--


You received this message because you are subscribed to the Google Groups "ArangoDB" group.


To unsubscribe from this group and stop receiving emails from it, send an email to arangodb+u...@googlegroups.com.


To view this discussion on the web visit https://groups.google.com/d/msgid/arangodb/6bfb59ce-375a-441e-8521-53688f879effn%40googlegroups.com.


Marcela Guerrero

unread,
Aug 26, 2020, 12:36:43 PM8/26/20
to ArangoDB
It happens that I am doing a migration process from Mysql to ArangoDB for academic reasons. Against this, in reading I have found that ArangoDb is quite flexible. However, I have doubts about passing the data from my tables to documents, mainly when I come from a schema with one-to-many and many-to-many relationships. 
I found that for one to many you can work directly in this way https://www.arangodb.com/docs/stable/aql/examples-join.html However, it is not clear to me how to work many to many if I must necessarily work it as edges or documents 

Kerry Hormann

unread,
Aug 26, 2020, 5:30:40 PM8/26/20
to aran...@googlegroups.com
ArangoDB does not require that you use graph methods in your query, nor does it really penalize you if you choose not to.  It is possible to keep a "primary key" and/or "foreign key" attribute in each document (as is done with normalized SQL tables) and use the FOR ... IN ... FILTER mechanism to "join" collections - no edges required (just be sure you have indexes - use explain to see if they're being used!).  There are performance gains to be had when using graphs because there are some optimizations built into the engine, but they may be minor enough that you can forge ahead without.

To use edges instead of "joins," you will have to create individual edge documents for each relation.  Obviously, this would be ridiculous to do by hand, so scripting is necessary prior to or after import.  Just iterate over each document in collection A, find a match in collection B, then insert an edge with those from/to attributes.  Also, I recommend defining a named graph so the engine knows that edge collection C contains edges that go from collection A to collection B.  You can also use an anonymous graph if you want to sacrifice integrity and flexibility for some speed.

Message has been deleted

Marcela Guerrero

unread,
Aug 26, 2020, 9:16:41 PM8/26/20
to ArangoDB
I really appreciate your help, the truth is that the information you give me is quite useful. Finally I would like to ask you something. In my case I am doing a migration from mysql to arangodb and I worked the relationship one to one in the way you mentioned and from many to many creating an edge, however in the relational model I have a table that has more than two relationships many to many and in that case I don't know how to work it because creating an edge type document only allows me to create a _from and a _to and I don't know how I could work that situation. For example, in the relational model, I have an  table called BILL,  that was the product of a many-to-many relationship of 3 tables, thus having 3 foreign keys. Could you give me some idea of ​​it. I would appreciate you infinitely.  

noel del rosario

unread,
Aug 26, 2020, 9:57:57 PM8/26/20
to aran...@googlegroups.com

On Thu, Aug 27, 2020 at 12:07 AM Marcela Guerrero <marcelagu...@gmail.com> wrote:
Can edges only be used for the graph data model? Or I can use it similarly as if it were a many-to-many relationship in the relational model. 
What happens to many-to-many relationships in ArangoDB in the event that there are more than two involved tables as evidenced in a relational model ?

--
Reply all
Reply to author
Forward
0 new messages