Vladimir Kotlyarski
Vladimir Kotlyarski

Reputation: 21

Gremlin delete Vertex recursively

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

Upvotes: 2

Views: 566

Answers (3)

JEDII29
JEDII29

Reputation: 26

If anyone is interested, the solution provided above g.V('SomeDataId').emit().repeat(out()).fold().unfold().drop()

also works with ExRam.Gremlinq. Here's how it work for me:

await g.V<Root>("id")        
    .Cast<Child>()
    .Loop(loop => loop
        .Repeat(__ => __
        .OutE<HasChild>()
        .InV<Child>())
        .Emit()
        .Until(__ => __.Not(_ => _.OutE<HasChild>())))
    .Fold()
    .Unfold()
    .Drop();

Upvotes: 0

Mayank rathi
Mayank rathi

Reputation: 11

Try this query, it works fine for me:

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

Upvotes: 1

stephen mallette
stephen mallette

Reputation: 46216

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()

Upvotes: 2

Related Questions