arangodb icon indicating copy to clipboard operation
arangodb copied to clipboard

Store trees in ArangoDB

Open caracal7 opened this issue 8 years ago • 7 comments

Which is the best practice for storing trees in ArangoDB? I need to use graph, edges & etc? But where to find examples of basic tree operations like read, path, insert, delete, move & etc?

Or I need to use Nested Sets & etc like when storing trees in MySQL?

Of course it is possible to store all tree in one row as JSON but it is not useful for manage tree and using keys from the tree especially if I work with big trees

P.S. sorry for my bad English((

caracal7 avatar Feb 26 '17 12:02 caracal7

You can do all of these things, it just depends on how you want to access and use the data.

If you want to use the graph features of ArangoDB the most sensible choice is using an edge collection to store the edges connecting the tree's vertices (which can be regular documents in document collections). This allows you to traverse the tree efficiently and use graph functions.

pluma avatar Feb 26 '17 14:02 pluma

Thank you for your fast reply)

I don't need any special graph features for trees. I want to store nested folders with unlimited depth and inside the folders store records or keys. I don't need data structure more optimised for reads or writes. I'm looking for easy way for organise tree(INSERT/DELETE/MOVE tree nodes and of course...read all children's for selected node) I'm not familiar with graph part of ArangoDB but I really like AQL) At the moment I think that more easy way is to store tree in Nested Sets format and I will need only one AQL query for every operation with tree. I think this is not Arango way) Maybe you know a good example of simple operations like insert/delete/move with regular tree graph?

P.S. sorry for my bad English and possibly stupid questions((

caracal7 avatar Feb 26 '17 15:02 caracal7

I think documentation for this global use case will be awesome. Store regular website menus, that require tree structure with ordering (important).

Something like (multiple root)

- Menu Position 1
  - Home
  - Products
    - New Products
    - Most sales
  - Categories
    - Computers
    - Tools

- Menu Position 2
  - Home
  - About Us

mhf-ir avatar Oct 04 '19 17:10 mhf-ir

Is there anyone who can help with this?

SultanNasyrovDeveloper avatar Feb 07 '24 10:02 SultanNasyrovDeveloper

Is there anyone who can help with this?

@SultanNasyrovDeveloper What kind of help do you need?

I can try to find my old sources to work with Nested sets using arangodb transactions

caracal7 avatar Feb 07 '24 16:02 caracal7

Is there anyone who can help with this?

@SultanNasyrovDeveloper What kind of help do you need?

I can try to find my old sources to work with Nested sets using arangodb transactions

First of all i need to understand why would you use this pattern to store tree in graph database? I though about just parent to child edge.

SultanNasyrovDeveloper avatar Feb 11 '24 08:02 SultanNasyrovDeveloper

First of all i need to understand why would you use this pattern to store tree in graph database? I though about just parent to child edge.

Just because I used to use it in relational databases before. And this pattern allows you to make very fast selections without recursion. Maybe in ArangoDB it's more fast and easy to use an edge collection and graph traverse but I didn't try it

caracal7 avatar Feb 11 '24 08:02 caracal7