I am trying to write a gremlin expression that will, for a given vertex, delete all the edges to and from it, and then delete the vertex itself.
I am using OrientDB 1.3-SNAPSHOT as my graph database.
This is my expression so far:
//The #8:1 just refers to a vertex
g.v('#8:1').bothE.each{ g.removeEdge(it) }.back(2)
I am expecting the above to delete the edges and then back 2, which should print out the node #8:1
. However, for some reason, I am getting this error:
Error: java.lang.NullPointerException
Why is this happening?
Finally, how do I go about removing the vertex? The docs showed that removeVertex()
requires an argument (which is the vertex). How do I pass the vertex from back(2)
into removeVertex()
?
Gremlin actually deletes all the edges for you if you delete the vertex. In my case, I simply had to do:
g.removeVertex(g.v('#8:1')); g.stopTransaction(SUCCESS);
This will delete the vertex and any edges that are associated with the vertex. Stop transation is required for gremlin to commit the change.
Now, as for why an error was thrown in the query for my statement. This is because each{}
is a grovvy construct, so we exit the pipe. To continue in the pipe, use sideEffect{}
instead.