简体   繁体   中英

ArangoDB Get Tree Root Nodes

I'm storing basic hierarchical game trees in ArangoDB as graphs. Each game tree has a start node, and each node (including the start node) 2-5 edges (actions). I have 2 collections, nodes for vertices and actions for edges.

I'm using the Node JS SDK and I'm trying to find the best way to query all start nodes? Should I add an isRoot property to nodes and query the nodes collection using that? Or should I query all nodes doing a filter using the actions collection to find nodes without inbound edges? Or a separate collection of start nodes?

Traversal or aggregation-based approaches to find root nodes will not be very efficient. The fastest option is probably to add an isRoot attribute that you can query for and potentially index.

You could also create an extra vertex that has an outgoing edge to every root node so that you can do a 1-hop traversal from this node to all root nodes. But that could get in the way if you want to traverse in the opposite direction and that node would be a supernode that one typically tries to avoid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM