Title: Gremlin delete Vertex recursively
Tags: gremlin;janusgraph
Question: I try to delete a Vertex with all child nodes with the gremlin query:
.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 &quot;someId&quot; was removed
But &quot;someId&quot; exists in the db!
Java + JanusGraph:
org.janusgraph:janusgraph-driver:0.5.3
org.apache.tinkerpop:gremlin-driver:3.5.0
Comment: On top of the answers given below, if by chance your graph has parallel bi-directional edges between the nodes being dropped, you may want to include a `simplePath` in the `repeat`, or do a `dedup` before the `drop`.


Here is another answer: 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()

Here is another answer: Try this query, it works fine for me:
g.V('SomeDataId').emit().repeat(out()).fold().unfold().drop()

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2021:00:07/22/21', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<gremlin><janusgraph>', 'Title': 'Gremlin delete Vertex recursively', 'ViewCount': 185, 'id': 68479695, 'user_AboutMe': None, 'user_AccountId': 9923973.0, 'user_DisplayName': 'Vladimir Kotlyarski', 'user_Reputation': 21.0, 'user_Views': 2.0, 'user_id': 7346237.0}}