orientdborientjs

OrientDB get Edges with shortestPath()


I have a Question about the shortestPath() Function of OrientDB. If I Query select shortestPath('#9:1', '#15:1', 'BOTH') against a OrientDB I just get the Vertex of the Path. But I also want the Edges between them. How can I SELECT both, the Vertex and the Edges?


Solution

  • You can use a javascript function.

    I used these records

    enter image description here

    enter image description here

    I used this code

    var g=orient.getGraph();
    var b=g.command("sql","select expand(shortestPath(" + start + "," + end + ", 'BOTH'))");
    var list=[];
    for(i=0;i<b.length-1;i++){
        var rid1=b[i].getId(); 
        var rid2=b[i+1].getId(); 
        var query="select from e where out = " + rid1 + " and in = " + rid2 + " limit 1";
        var edge=g.command("sql",query);
        list.push(b[i]);
        list.push(edge[0]);
        if(i==b.length-2){
            list.push(b[i+1]);
        }
    }
    return list;
    

    enter image description here

    Hope it helps.