Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CosmosDB Graph: How to update vertex having property with multiple values using gremlin?

According to cosmosDB graph documentation, a vertex can have property with multiple values. https://learn.microsoft.com/en-us/azure/cosmos-db/gremlin-support

So while adding vertex if we define multiple values for a property, it gets added.

Suppose my query is :

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

Result is:

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

But while updating vertex, if we update a property with multiple values.

Query is:

g.V('john').property('country', 'USA').property('country', 'India').property('country', 'China')

Result is:

[{"id":"john","label":"employee","type":"vertex","properties":{"country":
    [{"id":"7e5d9847-31e5-4a59-82f9-b78e744420a1","value":"China"}]}}]

How to update this property with multiple values?

like image 232
Jagrati Modi Avatar asked Mar 08 '23 18:03

Jagrati Modi


1 Answers

You're missing the list keyword that will allow you to add additional properties.

I'd recommend reading the Tinkerpop docs on VertexProperties

g.V('john').property(list, 'country', 'USA')
   .property(list, 'country', 'India')
   .property(list, 'country', 'China')
like image 74
Jesse Carter Avatar answered Mar 11 '23 07:03

Jesse Carter