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

Viewed 231
1 Answers

You can accomplish this using the project() step within Gremlin like this:

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

This will return your data formatted like this this:

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