Trying to find a Vertex using a variable injected earlier in the traversal
I am trying to add a series of vertices and edges to an existing graph. The newly created Vertex will be the
to
Vertex. From business logic, I will know the ID of the from
Vertex for the new Edge . I am able to create the new Vertex without any issue, but when I am having trouble grabbing the from
Vertex to create the edge. Is there a way to do this/what am I doing wrong?
4 Replies
This pattern is hard to implement for situations where you need to dynamically use the values in the
Map
to look-up an existing Vertex
. While there is probably a way to make it work, this pattern is a bit antiquated given the introduction of mergeV()
and mergeE()
which generally simplifies that query to something more like:
Is there any chance you could use this approach instead or are you using a version of Gremlin prior to 3.6.0?Yeah, I can do that. I am on 3.6.2. I think the reason that I wanted to use the
add
functions instead of the merge
function is that I wanted it to fail if there was a collision. Do you know if there is a way to set the OnMatch
to throw an error?
In this case I could do an addV and then know that the edge doesn't exist so the mergeE could only be a create. But if the merge functions are going to be more broadly capable it would still be good to know if there is a way to detect a collision from the mergeyou can use
fail()
step - the example from the docs shows its usage with onCreate
but you could just as easily apply it to onMatch
:
https://tinkerpop.apache.org/docs/current/reference/#mergevertex-stepAwesome. Thanks