Jagrati Modi
Jagrati Modi

Reputation: 2088

CosmosDB Graph: How to update a value of property of vertex having multiple values using gremlin?

Suppose my query is :

g.addV('employee').property('id', 'john').property('country', 'USA').property('country', 'India')

which adds property country with two values i.e USA and India.

[
 {
  "id":"john",
  "label":"employee",
  "type":"vertex",
  "properties":{
                "country":[
                          {
                           "id":"5dc2aaf6-cb11-4d4a-a2ce-e5fe79d28c80",
                           "value":"USA"
                          },
                          {
                           "id":"fcf4baf6-b4d5-45a3-a4ba-83a859806aef",
                           "value":"India"
                          }
                          ]
                }
 }
]

Now I want to change one of the existing values. For example 'India' to 'China'.

What will be query for that?

Upvotes: 4

Views: 881

Answers (3)

Daniel Kuppitz
Daniel Kuppitz

Reputation: 10904

In a single query it's just that:

g.V().has('id', 'john').
  sideEffect(properties('country').hasValue('India').drop()).
  property(list, 'country', 'China')

Upvotes: 4

Tom Sun
Tom Sun

Reputation: 24569

We could drop the 'India' value firstly and then add the 'China'. I test it with following query on my side, it works correctly.

g.V().has('id', 'john').properties('country').hasValue('India').drop()
g.V().has('id', 'john').property(list, 'country', 'China')

Upvotes: 2

Robert Dale
Robert Dale

Reputation: 51

g.V().has('employee','id', 'john').property('country', 'China')

Upvotes: 0

Related Questions