adding edges to multiple vertices at once

Hey all. Working with tinkerpop on Cosmos Gremlin DB which is horrific. Wondering is there anyway around adding an edge from multiple vertices at the same time? For example g.V(vertexId).addE(“linked_to”).from(__.V(vertex2,vertex3)) Thanks for any help. This has stumped me for three days 😂
5 Replies
JohnAllen
JohnAllen12mo ago
To give a little more insight into what I am trying to do. Let’s say we have a db g.addV(“user”).property(“name”,”one”).property(“id“,”1”) g.addV(“user”).property(“name”,”two”).property(“id“,”2”) g.addV(“job”).property(“name”,”three”).property(“id“,”3”) What I want to do is add user one and two to the job like this g.V(“1”,”2”).addE(“works_at).to(__.V(“3”)) But it doesn’t seem to work
spmallette
spmallette12mo ago
if g.V("1","2") returns two vertices, and V("3") returns one vertex then you should get two edges created. if your example there is literally what you are doing then the problem is likely that none of those are returning any vertices at all. you've added a property called "id" but that doesn't refer to the unique identifier for the vertex. if you want that then you need to use T.id as in property(T.id, "1"). V("1") will then return a vertex in that case.
JohnAllen
JohnAllen12mo ago
Thanks for the reply. In MS’s Cosmos implementation of tinkerpop we can use .property(“id”,X) to set the id of the vertex to X. g.V(X) will return the vertex I expect. g.V(X,Y) returns two vertices… So I should be able to do what I am trying to do. Can’t work this out.. I think it’s something to do with MS’s janky tinkerpop version
spmallette
spmallette12mo ago
@KelvinL there's an interesting @cosmosdb difference I wasn't aware of ☝️ Well, @.johnallen perhaps it is something to do with the use of to(V("3")) . I presume that CosmosDB let's you do:
g.V("1").as("1").
V("2").as("2").
V("3").as("3").
addE("works_at").from("1").to("3").
addE("works_at").from("2").to("3")
g.V("1").as("1").
V("2").as("2").
V("3").as("3").
addE("works_at").from("1").to("3").
addE("works_at").from("2").to("3")
it's not nice but it's one query at least
JohnAllen
JohnAllen12mo ago
@spmallette thanks I will try that when I get back from vacation. Will be interesting to see the executionProfile as execution time is a real concern for this query. Will update regardless
Want results from more Discord servers?
Add your server
More Posts