Search code examples
orientdbgremlin

Gremlin: Group by multiple properties from two different vertices


I have a vertex called 'Community' with property 'name', and Communities have a relationship with vertex 'People'. People have property 'id'. People can belong to multiple Communities. I want to build a gremlin query that groups all People, by 'id', that belong to each 'community'. It can either be two columns "ID" and "Commmunity" where there would be duplicate of both, or it can be unique "Community" names with People ids separated by commas.Any ideas?


Solution

  • Shot in the dark here, based on the provided information:

    g.V().hasLabel('Community').
      group().
        by('name').
        by(__.in('belongsTo').values('id').fold())