Search code examples
orientdbnosql

OrientDB edge in the graph mode


I have two v class: vuser and vlang and e class: speaks.

So: vuser -> speaks -> vlang

Then I´m trying to see in my graph the users that speaks 'ar' and my query is the next:

select expand(in('speaks')) from vlang where lang = 'ar'  

With this, I see the users but not the vertex from vlang and the edge. How can I show the edge and the vlang where lang = 'ar'? I have read the OrientDB doc but I didn´t see this question type.

Thanks in advance.


Solution

  • If you are on v 2.2 you can use a MATCH for this:

    MATCH
    {class:vlang, as:lang, where:(lang = 'ar')} <-speaks- {as:user}
    RETURN $elements
    

    this returns user and lang vertices. If you also need the edge, you can use this syntax:

    MATCH
    {class:vlang, as:lang, where:(lang = 'ar')}
      .inE("speaks"){as:theEdge}
      .outV(){as:user}  
    RETURN $elements
    

    This will return single edges/vertices only once, as a separate item in the result set.

    If you want to see the single patterns, you can change the RETURN clause: RETURN $patterns

    Full syntax here: http://orientdb.com/docs/2.2.x/SQL-Match.html