Conditionally update one vertex property when another property matches a certain provided value

Stack Overflow
Update Vertex Properties when property 'A' matches property 'B'
I have a vertex with meta properties on it, like below, and need to update the properties & the attached meta properties. When an Id matches the passed value on hasId the data needs to be updat...
1 Reply
spmallette
spmallette10mo ago
Interesting question - it's not quite what I expected at first:
gremlin> g.addV('person').property('val','green')
==>v[0]
gremlin> g.V().has('val','green').properties('val').property('currentDate','12-12-2023').property('previousDate','10-10-2023')
==>vp[val->green]
gremlin> g.V().properties().elementMap()
==>[id:1,key:val,value:green,currentDate:12-12-2023,previousDate:10-10-2023]
gremlin> g.V(0L).hasLabel('person').as('a').properties('val').hasId(1).property('currentDate','1-1-2024').select('a').property('val','red').iterate()
gremlin> g.V().valueMap()
==>[val:[red]]
gremlin> g.V().properties('val').elementMap()
==>[id:2,key:val,value:red]
gremlin> g.addV('person').property('val','green')
==>v[0]
gremlin> g.V().has('val','green').properties('val').property('currentDate','12-12-2023').property('previousDate','10-10-2023')
==>vp[val->green]
gremlin> g.V().properties().elementMap()
==>[id:1,key:val,value:green,currentDate:12-12-2023,previousDate:10-10-2023]
gremlin> g.V(0L).hasLabel('person').as('a').properties('val').hasId(1).property('currentDate','1-1-2024').select('a').property('val','red').iterate()
gremlin> g.V().valueMap()
==>[val:[red]]
gremlin> g.V().properties('val').elementMap()
==>[id:2,key:val,value:red]
but I think that's just how metaproperties work. when you update a property with a single cardinality it's like removing the property and adding it back. when it is removed you effectively lose the related metaproperties with the old value. you'd have to add those back too. Rather than this sort of structure:
g.V(0L).hasLabel('person').as('a').
properties('val').hasId(1).
property('currentDate','1-1-2024').
select('a').property('val','red')
g.V(0L).hasLabel('person').as('a').
properties('val').hasId(1).
property('currentDate','1-1-2024').
select('a').property('val','red')
I think you'd want something more like:
g.V(0L).hasLabel('person').
filter(properties('val').hasId(1)).
property('val','red').
properties('val').hasValue('red').
property('currentDate','1-1-2024')
g.V(0L).hasLabel('person').
filter(properties('val').hasId(1)).
property('val','red').
properties('val').hasValue('red').
property('currentDate','1-1-2024')
@KelvinL any chance I'm missing something here in terms of how metaproperties work?