node.jsorientdborientdb2.2orientjs

Querying edge ID between two vertex IDs


I have this User vertex and friends edge. I know two of the users who are friends and one of them wants to unfriend the other. How am I supposed to delete that edge between given vertexes?

So far running both DELETE EDGE FROM :player1 TO :player2 WHERE @class = "friends" and DELETE EDGE FROM :player2 TO :player1 WHERE @class = "friends" (with proper params ofc.) to make sure it's deleted works fine for me but that doesn't feel elegant enough.


Solution

  • You should be able to do it in a single query:

     DELETE EDGE friends FROM [:player1, :player2] TO [:player1, :player2]
    

    In case you also have edges from a vertex to itself (eg. from player1 to player1) and you don't want to delete them, you can add a condition:

     DELETE EDGE friends FROM [:player1, :player2] TO [:player1, :player2]
     WHERE out <> in