使用 Gremlin 获取顶点及其直接 'child' 顶点

Getting vertices and their immediate 'child' vertices with Gremlin

我有一组数据如下所示:

我可以使用超级简单的 g.V('group_id').in('user').valueMap() 来检索所有用户及其属性。我也可以检索角色,但不知何故,我无法一次检索所有角色。

我需要得到的是这样的:

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

我试过映射、联合,但要么我得到一组东西,比如用户,要么角色,但从来没有两者。

我认为你需要的只是

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