Reputation: 1600
I've worked out a traversal but would like to change how the result is structured to make it cleaner to extract in my Java code.
I want all the group vertices that my user is a member of along with a count of the group's total membership. I've used valueMap as that makes it nice to extract in the client Java
g.V().has('user','name','james').out('member').group().by(valueMap(true, 'name','image')).by(inE('member').count()).unfold()
which gives me
==>{image=[images/groups/group6.jpg], label=group, name=[Boxing Lovers], id=c1db7d33-a24c-4981-8ee8-950371789637}=10
==>{image=[images/groups/group4.jpg], label=group, name=[Hiking Disciples], id=d2da3866-1922-4c00-8895-21ab2e099243}=11.
How would I add the membership count to the HashMap with the group details, like below?
==>{image=[images/groups/group6.jpg], label=group, name=[Boxing Lovers], id=c1db7d33-a24c-4981-8ee8-950371789637, membership=10}
==>{image=[images/groups/group4.jpg], label=group, name=[Hiking Disciples], id=d2da3866-1922-4c00-8895-21ab2e099243, membership=11}
Upvotes: 1
Views: 204
Reputation: 14391
Rather than use valueMap
you could use project
. Here's an example using the air-routes graph.
gremlin> g.V().has('region','US-TX').
project('id','label','city','count').
by(id).
by(label).
by('city').
by(out().count()).
limit(3)
==>[id:3,label:airport,city:Austin,count:80]
==>[id:8,label:airport,city:Dallas,count:250]
==>[id:11,label:airport,city:Houston,count:197]
Upvotes: 1