Search code examples
orientdborientdb2.2

OrientDB query compare


I have the following doubt to query in OrientDB.

I have three vertex users, events and sports.

First users choose sports and at that point the has_sport edge is created, which has the 'out' on the user and 'in' on the sports.

And having some events registered by other users as follows, users-> events-> sports, users create edge 'out' and 'in' events and events edge 'out' and 'in' sports.

Now the question of how to do the query, I want to make a query that returns the events to the user according to the sports that he chose. In other words, to see if the user sports is equal to the events sport.

Vertex: users, events, sports Edges: has_sport, has_event

Image graph

Sorry for my bad english hehe

Thank you

EDIT

    SELECT expand(event) FROM (
      MATCH 
        {class:users, as:user, where:(userId = ?)} -has_sport-> {as:sport},
        {class:events, as:event} -has_sport-> {as:sport},
        {as:user} -has_sport-> {as:sport}
    RETURN event
    )

Solution

  • You can consider using a MATCH statement:

    MATCH 
      {class:User, as:user, where:(userId = ?)} -has_event-> {as:event} -has_sport-> {as:sport},
      {as:user} -has_sport-> {as:sport}
    RETURN event
    

    This will return the event RIDs. If you want expanded records, you can wrap it in a SELECT expand() eg.

    SELECT expand(event) FROM (
      MATCH...
    )