简体   繁体   English

如何在 ArangoDB 中获取图的根节点的键?

[英]How to get the root node's key of a graph in ArangoDB?

I have a graph in ArangoDB whose root node is 'X'.我在 ArangoDB 中有一个图,其根节点是“X”。 Now "a,b,c,d,e,f" are the siblings of 'X' direct or grand grand siblings.现在“a、b、c、d、e、f”是“X”直系兄弟姐妹或曾孙兄弟姐妹的兄弟姐妹。 Now from a given siblings node "a,b,c,d,e or f" I want to get to node 'X'.现在从给定的兄弟节点“a、b、c、d、e 或 f”我想到达节点“X”。 Is there any general AQL query to traverse directly to the root node of any graph ?是否有任何通用 AQL 查询可以直接遍历任何图的根节点?

To provide an exact example I would need to know a bit more, but this is one of several solutions.为了提供一个确切的例子,我需要了解更多,但这是几种解决方案之一。

Assuming that the nodes are connected by "child" edges and the direction of the edges go from parent to child.假设节点由“子”边连接,边的方向从父到子。 You would traverse the tree up or INBOUND你会遍历树向上或INBOUND

FOR v,e,p IN 1..50 INBOUND '(id of starting node a,b,etc.)' child RETURN p.vertices

If you know how many hops maximum to the root, change the 50 to that value.如果您知道根的最大跃点数,请将 50 更改为该值。

This statement will return all of the paths and intermediate paths from the starting node through the child links to the head node.该语句将返回从起始节点通过子链接到头节点的所有路径和中间路径。 To return only the path to the head node, you would have to filter out the intermediate paths.要仅返回到头节点的路径,您必须过滤掉中间路径。 This could be done with a check to see that there is no parent vertex.这可以通过检查是否没有父顶点来完成。

FOR v,e,p IN 1..50 INBOUND '(id of starting node a,b,etc.)' child 
  FILTER LENGTH(EDGES(child,v._id,'inbound'))==0 RETURN p.vertices

which will filter out all paths that do not end at a root vertex.这将过滤掉所有不在根顶点处结束的路径。

RHSMan's answer helped me but here is cleaned up a bit RHSMan 的回答帮助了我,但这里已经清理了一点

LET ref_people = (
    FOR p IN people RETURN p._id
)
LET l = (
     FOR id IN ref_people 
         FOR link IN links FILTER id == link._from RETURN id
)

RETURN MINUS(ref_people, l)

I came across this as I had the same problem but the above is outdated:我遇到了这个问题,因为我遇到了同样的问题,但上面已经过时了:

I did the following:我做了以下事情:

let ref_items = (for s in skills
return s._id)


let c = (for item in ref_skills
for sk in skill_skill
    filter item == sk._to

    return item)
return MINUS(ref_skills, c)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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