I have a document collection containing tree nodes and an edge collection containing "is child of" like this:
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:
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:
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 is used for internal key attribute, and it has to be a string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With