using mergeV/E
Hello I’m trying to upgrade my gremlin package to latest and running into an issue with mergeE and mergeV. I’m using this to replace some coalace steps that I was using before. How do you set the label in mergeV() for the particular vertex. I see I can pass the T.label in the map but, I don’t understand what the equivalent of this would be for JavaScript
Solution:Jump to solution
Another approach would be to inject a list of maps and do something like this:
```
var newNodes = []
newNodes.push(new Map([[(t.id),1],...
4 Replies
This is how I got it to work...
Thank you! Is that really the only way? Creating the verticies and adding properties was just as easy as using mergeV and passing a map as the argument the only thing is that these only have the default node label) I understand the need to pass the traverser for the T.label value but, why is the id passed twice in this case and the need for the option? It kind of defeats the purpose of replacing the coalace pattern if it’s just as complicated especially since setting the label is essential in a graph
Solution
Another approach would be to inject a list of maps and do something like this:
Something that was not clear to me was how we handled situations where there's not an exact match for a vertex/edge and all associated properties. So if you are just adding new vertices/edges and the properties are an exact match, then
mergeV()
will return the existing vertex/edge. If not an exact match, you'll get an exception (unless you use the onMatch
option to handle those situations).
So for example, if I already had a Person vertex with ID 3, name Jane, and address 222 5th Avenue, then merge would just return that vertex. But if I already had a Person vertex with ID 3 and different property values, then this would throw an exception for a vertex that already exists (again, unless you use the onMatch
option to handle those cases).