Delete vertex with their child edges and all vertices

Hi I want to delete child vertices.
When I’m passing argument of vertex id to perform delete operation it’s should delete all the backward edges and their vertices, sub vertices (whole child tree)
e.g delVerticesById - should delete upcoming all the edge and vertices
v1 - v2 -v3 -v4 -v5
if I’m deleting v2,
child vertices of v3,v4,v5 that also want to delete.
could you please help with this.

@jvramana You can do something like the following - Feel free to modify it as you would like.

In this example, we have a start vertex (ie. v2) and would like to delete 3 child nodes you would just add depth 3.

CREATE QUERY basicQuery(VERTEX start_node, INT depth) FOR GRAPH myTest{

    OrAccum @visited = false;
    ListAccum<VERTEX> @@vertex2Del;
    SumAccum<int> @@loop=0;
    @@vertex2Del += start_node;

    Start = {start_node};
    Start = SELECT v
            FROM Start:v
            ACCUM v.@visited = true;

    WHILE (@@loop < depth) DO
        Start = SELECT v
                FROM Start:u - (:e)->:v
                WHERE v.@visited == false
                ACCUM v.@visited = true, @@vertex2Del += v;

        @@loop += 1;
   END;
  
   FOREACH v IN @@vertex2Del DO DELETE v;
   END;

   PRINT @@vertex2Del;
}
1 Like