简体   繁体   English

如何确定arangodb树形图中的根对象?

[英]How can I determine root objects in an arangodb tree graph?

I have a document collection containing tree nodes and an edge collection containing "is child of" like this: 我有一个包含树节点的文档集合和一个包含“is child of”的边集合,如下所示:

Folders=[
{_key:"1",name:"Root1"},
{_key:"2",name:"Root2"},
{_key:"3",name:"Root1.Node1"},
{_key:"4",name:"Root1.Node2"}]

FolderRelations=[
{_from:"Folders/3",_to:"Folders/1"},
{_from:"Folders/4",_to:"Folders/1"}
]

Now I would like to determine which Folder items are root objects in that tree (all objects that have no outbound relation). 现在我想确定哪些文件夹项是该树中的根对象(所有没​​有出站关系的对象)。

Maybe, I am a bit stuck in thinking SQL, I would like to carry out something like: 也许,我有点陷入思考SQL,我想执行类似的事情:

SELECT * 
FROM Folders 
WHERE NOT EXIST (SELECT * FROM FolderRelations WHERE FolderRelations.FromKey=Folders.Key)

For using the traversal and path functionality, I have no vertex to start with. 为了使用遍历和路径功能,我没有顶点开始。

here is an AQL example that should solve your problem: 这是一个AQL示例,可以解决您的问题:

for f in Folders
filter LENGTH( EDGES(FolderRelations, v._id, "outbound")) == 0
return f

you will get a list of all vertices that have no folder above in the hierarchy. 您将获得层次结构中没有上述文件夹的所有顶点的列表。

but be aware: saving {key:1} will not have the desired effect, you have to set: 但请注意:保存{key:1}将无法获得所需的效果,您必须设置:

{_key: "1"}

_key is used for internal key attribute, and it has to be a string. _key用于内部键属性,它必须是一个字符串。

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

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