Ian
Ian

Reputation: 3898

Gremlin - how to assign a list of values to a new property, for multiple vertices

Say I have a list of three vertices with IDs 123, 456, and 789.

g.V([123,456, 789])

How can I add a new property called say testproperty, for which I have a list of values, ['a', 'b', 'c'], which I want to add at the same time?

The pseudo gremlin code - for illustration - and which doesn't work is:

g.V([123,456, 789]).property('testproperty', ['a', 'b', 'c'])

To be clear, I want a mapping between the two lists, so g.V(123).property('testproperty', 'a'), g.V(123).property('testproperty', 'b') etc.

So, g.V([123,456,789]).valueMap() should return:

==>{testproperty=[a]}
==>{testproperty=[b]}
==>{testproperty=[c]}

Upvotes: 0

Views: 629

Answers (1)

stephen mallette
stephen mallette

Reputation: 46206

Here's one way to do it:

gremlin> data = [1:'a',2:'b',3:'c']
==>1=a
==>2=b
==>3=c
gremlin> g.inject(data).as('d').
......1>   V(data.keySet()).as('v').
......2>   property('testproperty', select('d').select(select('v').by(T.id)))
==>v[1]
==>v[2]
==>v[3]
gremlin> g.V(data.keySet()).valueMap(true)
==>[id:1,label:person,testproperty:[a],name:[marko],age:[29]]
==>[id:2,label:person,testproperty:[b],name:[vadas],age:[27]]
==>[id:3,label:software,testproperty:[c],name:[lop],lang:[java]]

Upvotes: 1

Related Questions