Gremlin upsert on a vertex but preventing updates on a particular property on a vertex during upsert

Hi, Following is an upsert query on a vertex with label 'stvertex' and I am required to initialize and default the 'flagProp' to 0 only during creation of this vertex but during update I am required to prevent any update only on 'flagProp' while rest of the property should update, below is one of the approach I took: g.V(id).fold().coalesce(unfold(), __.addV(‘stvertex’) .property(T.id, id).property(Cardinality.single, flagProp,0)) .property(Cardinality.single, name, nameValue) .property(Cardinality.single, station, stationValue) .property(Cardinality.single, base, baseValue).next() The above query only works for creation of new vertex I am looking for some help to write the correct query which works for update as well
Solution:
Hi Salman, Better to use mergeV step. You may set flagProp in onCreate option, and create/update all other properties in both onCreate and onMatch, something like `gremlin> g.mergeV([(T.label):'stvertex'])....
Jump to solution
3 Replies
Solution
Valentyn Kahamlyk
Hi Salman, Better to use mergeV step. You may set flagProp in onCreate option, and create/update all other properties in both onCreate and onMatch, something like gremlin> g.mergeV([(T.label):'stvertex']). ......1> option(Merge.onCreate,[flagProp:0, name:'test1']). ......2> option(Merge.onMatch,[name:'test2']) ==>v[17] gremlin> g.V(17).elementMap() ==>[id:17,label:stvertex,name:test1,flagProp:0] gremlin> g.mergeV([(T.label):'stvertex']). ......1> option(Merge.onCreate,[flagProp:0, name:'test1']). ......2> option(Merge.onMatch,[name:'test2']) ==>v[17] gremlin> g.V(17).elementMap() ==>[id:17,label:stvertex,name:test2,flagProp:0]
Yang Xia
Yang Xia9mo ago
Also just to throw in the docs link on MergeV, there are some additional examples and explanations of the step there https://tinkerpop.apache.org/docs/current/reference/#mergevertex-step
Salman
Salman9mo ago
Thank you Velentyn and Yang for the suggestion I will try it out
Want results from more Discord servers?
Add your server