Search code examples
orientdbgremlin

Gremlin: Find duplicates of a vertex by 'name' property and execute as list of 'id'


The below code groups all userProfileTemplates by name, finds where there are duplicates and then projects the "name" of the userProfileTemplate where the count of name is > 1. I want to find duplicates by "name", but I want to execute it as a list of "Id" (Id is a property of userProfileTemplate). Any suggestions?

g.V().hasLabel('userProfileTemplate').group().by(values('name').fold()).unfold().filter(select(values).count(local).is(gt(1))).select(keys)unfold().project('Duplicate User Profiles')

Update: The below is executing a column named "value" with the multiple 'id' that correspond to the duplicate 'name', separated by commas in betweeen brackts.

g.V().hasLabel('userProfileTemplate').group().by('name').by('id').unfold().filter(select(values).count(local).is(gt(1))).select(values)

I would like to also execute a column that shows the corresponding 'name' for all duplicate ids.


Solution

  • It's almost what you already have, you only need to add another by().

    g.V().hasLabel('userProfileTemplate').
      group().
        by('name').
        by('Id').
      unfold().
      filter(select(values).count(local).is(gt(1))).
      select(keys)