I'm trying to drop an edge and add a new edge between two vertices. How do I do that in Tinkerpop3?
def user = g.V().has("userId", 'iamuser42').has("tenantId", 'testtenant').hasLabel('User');
user.outE("is_invited_to_join").where(otherV().has("groupId", 'test123')).drop();
def group = g.V().has("groupId", 'test123').has("tenantId", 'testtenant').hasLabel('Group').next();
user.addEdge("is_member_of", group);
This is the error I get on gremlin shell:
No signature of method: org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal.addEdge() is applicable for argument types: (java.lang.String, com.thinkaurelius.titan.graphdb.vertices.CacheVertex) values: [is_member_of, v[8224]]
Thank you.
The Gremlin Console tutorial discusses this issue a bit. You are not iterating your traversal. Consider the following:
Great! The person
Vertex
is stored in the "person" variable...or is it?Apparently it is not a
Vertex
. "person" is aTraversal
, the console sees it as such and iterates it for you which is why you get "v1" in the output. Note that the traversal is now "done":You need to iterate the
Traversal
into your variable - in this case, usingnext()
:Note that you will have further problems down the line in your script because you are using what will now be a
Vertex
as aTraversal
, so this line:will now fail with a similar error because
Vertex
will not haveoutE()
. You would need to do something like:If you would like to add an edge and drop the old one in the same traversal, you could do something like this:
Arguably, that might not be as readable as breaking it into two or more separate traversals, but it can be done.