Search code examples
sqlorientdb

OrientDB: Query tree


I have a directory-like tree structure in OrientDB:

Node(name='a')->Connection->Node(name='b')->Connection->Node(name='c')

create class Node extends V
create class Connection extends E

let a = create vertex Node set name = 'a'
let b = create vertex Node set name = 'b'
create edge Connection from $a to $b
let c = create vertex Node set name = 'c'
create edge Connection from $b to $c

How can I select Node(name='c') if I know the path 'a'->'b'->'c'?

Keep in mind that all names may be equal on different levels of hierarchy: like instead of 'a', 'b', 'c' it can be 'a', 'a', 'a' but all nodes are different.


Solution

  • try

    SELECT expand(o) from
    
    (MATCH
    {
     class: Node,
     where: (name='a')
    }
    
    .out('Connection')
    
    .out('Connection')
    {
     as: o
    }
    
    RETURN o)
    

    or without MATCH

    select expand(out('Connection').out('Connection')) from Node where name='a'
    

    is this what are you looking for?