oPolo
oPolo

Reputation: 576

Rename property with Gremlin in Azure Cosmos DB

Some of our codebase has changed, so it now expects the vertices that used to have a property with the name "Sdg" to now have a property with the name "causeType" and with the same value instead.... In short, a renaming of the property.

I have tried quite a bit at this point, and... Am a bit surprised of how hard it has been to figure out how to search the graph, and do a renaming when needed.

The closest I have come is the following query:

g.V().has('sdg').as('vertexWithOldProperty').property('causeType', value(select('vertexWithOldProperty').select('sdg')))

...It does not work due to the error:

Gremlin Query Compilation Error: Unable to bind to method 'value', with arguments of type: (GraphTraversal) @ line 1, column 68. Unable to bind to method 'property', with arguments of type: (String)

The idea was to run over the graph and remember every vertice that had the old value. Then I would add the new property with the same value to them... And for simplicity/feasibility I decided to just ignore the old value instead of removing it.

Can anyone help me or lead me in the right direction?

Thanks!

Upvotes: 2

Views: 1357

Answers (1)

noam621
noam621

Reputation: 2856

Maybe there's a better way, but I think this should work for you:

g.V().has('sdg').property('causeType', values('sdg'))

And if you want to delete the old property

g.V().has('sdg').property('causeType', values('sdg')).properties('sdg').drop()

Upvotes: 4

Related Questions