5

I'm using Titan 1.0 Version and Gremlin Server with REST Api for creating and updating Vertex details. How can I delete the vertex using vertexId?

2 Answers2

13

you can use drop property to delete a vertex like :

g.V(vertexId).drop()

you will find more details about drop property on following link :

TinkerPop3 Documentation

  • 7
    `g.V(vertexId).next().remove()` will also do the trick. If you have the vertex already then simply `v.remove()`. Any of the 3 will serve. – Filipe Teixeira May 19 '16 at 08:18
  • Please note that `g.V(vertexId).drop()` without iterating the result will only work in Gremlin console that iterates results automatically. In a Java program, to actually trigger the removal, iteration needs to be requested like this: `g.V(vertexId).drop().iterate()` – Roman Puchkovskiy Mar 02 '21 at 07:52
  • Also, if the `Vertex` instance you have is a `ReferenceVertex` (which seems to be the case when you are working via a remote connection), `v.remove()` will not work at all as removal is not supported for `ReferenceVertex`. – Roman Puchkovskiy Mar 02 '21 at 07:57
2

You can use :

 g.V().hasId(vertexId).drop()

In the hasId method pass the id of the vertex you want to delete

Abhishek Raj
  • 476
  • 2
  • 14