Gremlin delete Vertex recursively

Viewed 185

I try to delete a Vertex with all child nodes with the gremlin query:

g.V()
    .hasId(someId)
    .union(fold().unfold(), repeat(in()).emit())
    .drop()
    .iterate()

Unfortunately I get an Error:

org.apache.tinkerpop.gremlin.driver.exception.ResponseException: Vertex with id "someId" was removed

But "someId" exists in the db!

Java + JanusGraph:

org.janusgraph:janusgraph-driver:0.5.3

org.apache.tinkerpop:gremlin-driver:3.5.0

2 Answers

It may help to aggregate(local) the things to drop first and then remove them - something like:

g.withSideEffect('x',[] as Set).
  V().hasId(someId).aggregate(local,'x').
  repeat(in()).emit()).aggregate(local,'x').
  cap('x').
  drop()

Try this query, it works fine for me:

g.V('SomeDataId').emit().repeat(out()).fold().unfold().drop()
Related