如何按 parent 分组并在 gremlin 中收集 child 的所有 属性 值?

How to group by parent and collect all property values of child in gremlin?

我想将所有节目及其相关类型收集在一起。 GENRES 是 child 与 SHOWS

的关系

Sample gemlin graph 这样输出类似于:

"1" [a,b]
"2" [c,d]

示例图:https://gremlify.com/x8i8stszn2

您可以使用 Gremlin 中的 project() step 完成此操作,如下所示:

g.V("2789").out('WATCHED').hasLabel('SHOW').
project('show', 'genre').
  by('NAME').
  by(out('HAS_GENRE').values('NAME').fold())

这将 return 您的数据格式如下:

[
  {
    "show": 1,
    "genre": [
      "a",
      "b"
    ]
  },
  {
    "show": 2,
    "genre": [
      "c",
      "d"
    ]
  }
]