Gremin mergeV() Upsert: knowing whether the vertex was added or not

31 views
Skip to first unread message

Zhen Lian

unread,
Dec 2, 2023, 7:17:01 AM12/2/23
to Gremlin-users
Hi all!

In this StackOverflow post: https://stackoverflow.com/questions/49758417/cosmosdb-graph-upsert-query-pattern/49758568#49758568 , there was an awesome discussion of using fold()/coalesce()/unfold() style pattern for upserting vertex, and knowing whether the vertex has been added or obtained:

g.V().has('event','id','1').
  fold().
  coalesce(unfold().
           project('vertex','exists').
             by(identity()).
             by(constant(true)),
           addV('event').property('id','1').
           project('vertex','exists').
             by(identity()).
             by(constant(false)))

The post also made the update that there was a more advanced pattern using mergeV(). I wonder if we can "translate" the above to the more advanced mergeV() pattern?

Any help/insight is much appreciated!

Best Regards,
Zhen Lian

Zhen Lian

unread,
Dec 7, 2023, 4:50:59 PM12/7/23
to Gremlin-users
Got a very good answer with the same question on StackOverflow: https://stackoverflow.com/questions/77587723/gremin-mergev-upsert-knowing-whether-the-vertex-was-added-or-notside-effect
Posting it here as well for posterity. 

Reply all
Reply to author
Forward
0 new messages