g.V().has('key', 'value1').fold().coalesce(__.unfold().property(single, 'non-key', '5'), __.addV('label').property(single, 'key', 'value1').property(single, 'non-key', '5')).next()g.V(source_user).out('user_target_link').hasId(target).toList() g.V(source_user).coalesce(outE('user_target_link').filter(inV().hasId(target)),
addE('user_target_link').to(V(target)))
--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/c04ff72f-9add-44bf-a5b6-ddabd599f62d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
>>> g.V(source_user).outE().toList()
[]
>>> edge = g.V(source_user).coalesce(outE('user_target_link').filter(inV().hasId(target)), addE('user_target_link').to(V(target))).next()
>>> g.V(source_user).outE().toList()
[e[d6b5293f-27dd-d16c-65ed-77f614dc83d7][68b522ed-46ec-fab8-4437-cd413d2a4731-profile_link->b8b522ed-46fa-3b60-5c5e-a306c15cbd46]]
>>> edge = g.V(source_user).coalesce(outE('user_target_link').filter(inV().hasId(target)), addE('user_target_link').to(V(target))).next()
>>> g.V(source_user).outE().toList()
[e[d0b5293f-31dc-24f7-1d4e-739590c6a01e][68b522ed-46ec-fab8-4437-cd413d2a4731-profile_link->b8b522ed-46fa-3b60-5c5e-a306c15cbd46], e[d6b5293f-27dd-d16c-65ed-77f614dc83d7][68b522ed-46ec-fab8-4437-cd413d2a4731-profile_link->b8b522ed-46fa-3b60-5c5e-a306c15cbd46]]
g.V(source_user).outE('user_target_link').filter(inV().hasId(target))And with coalesce() it's pretty much the same story (even easier as you don't need to fold/unfold):g.V(source_user).coalesce(outE('user_target_link').filter(inV().hasId(target)),addE('user_target_link').to(V(target)))Cheers,Daniel
On Wed, Apr 24, 2019 at 11:24 AM <adam....@graphika.com> wrote:
I've been able to get an approximation of upsert for vertices (modify a vertex if it exists, and insert it if it doesn't) using .coalesce:--g.V().has('key', 'value1').fold().coalesce(__.unfold().property(single, 'non-key', '5'), __.addV('label').property(single, 'key', 'value1').property(single, 'non-key', '5')).next()
I'd like to do this for edges as well, but I can't figure out how to reference an edge between two vertices. I can do something like:g.V(source_user).out('user_target_link').hasId(target).toList()
to get the target vertex if there’s a path to the target vertex, but having done that I don’t see how to get a reference to the edge I just crossed to get there in order to modify it.Can someone shed some light on how to do this?Thanks!
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremli...@googlegroups.com.
gremlin> g = TinkerGraph.open().traversal()==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]gremlin> source = 1==>1gremlin> target = 2==>2gremlin> source_user = g.addV("user").property(id, source).next()==>v[1]gremlin> target_user = g.addV("user").property(id, target).next()==>v[2]gremlin> g.V(source_user).......1> coalesce(outE('user_target_link').filter(inV().hasId(target)),......2> addE('user_target_link').to(V(target))).next()==>e[0][1-user_target_link->2]gremlin> g.V(source_user).......1> coalesce(outE('user_target_link').filter(inV().hasId(target)),......2> addE('user_target_link').to(V(target))).next()==>e[0][1-user_target_link->2]gremlin> g.V(source_user).outE()==>e[0][1-user_target_link->2]
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/6c06d3e0-3a95-4890-b78c-29e546a36b60%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/fbb2d842-85e8-48aa-86e8-06a53405ccc1%40googlegroups.com.