E.T
E.T

Reputation: 1145

Getting vertices and their immediate 'child' vertices with Gremlin

I have a set of data that looks like this:

Users

I can go a super simple g.V('group_id').in('user').valueMap() to retrieve all the users and their properties. I can also retrieve the roles, but somehow, I can't retrieve all at once.

What I need to get is something like this:

==>{u={user_id=[474531d1], name=[User 1], email=[[email protected]]},r=[role A, role B, role C]}
==>{u={user_id=[474531d4], name=[User 2], email=[[email protected]]},r=[role A, role B]}
==>{u={user_id=[474531da], name=[User 3], email=[[email protected]]},r=[role C]}

I've tried with map, union, but either I get one set of things like users, or roles but never both.

Upvotes: 0

Views: 182

Answers (1)

Kelvin Lawrence
Kelvin Lawrence

Reputation: 14371

I would think all you need is something like

g.V('group-id').
  in('user').
  project('user','roles').
    by(valueMap()).
    by(out('role').valueMap().fold())

Upvotes: 1

Related Questions