Want to find nodes that have exact set of relationships

I'm a newbie with neo4j.
I'm looking to shape a query where I find all of the nodes with the label 'Person' who have a relationship to the exact same set of nodes with the label 'Role'.

So if Tom, Dick and Harry all [:IS_IN] the roles of 'Reporting' and 'Power User' then they should be listed out in the results.
Where as if Joe [:IS_IN] 'Reporting' and Mary [:IS_IN] 'Power User' then they would not be in the results.
Also, if Tom [:IS_IN] the role 'Processor', then that would not be listed in the results either, but his other relationships will.

And I'd like it to be output as: (1 row, two columns)

Users | Roles


Tom | Reporting
Dick | Power User
Harry |


Thanks for the help.

Hey @doug.gilmour,

Great to have you part of this community.

Based on your requirements, the use of the IN clause might be what you are looking for.
Here is the query that I would craft based on your requirement.

MATCH (p:Person)-[:IS_IN]->(r:Role)
WHERE r.role IN ['Reporting', 'Power User']
RETURN p.user, r.role

Tell us if that is starting to hit the mark.

Cheers,

-yyyguy

Thanks for getting back to me. The problem will be that I won't know the set of roles. It will be very dynamic. For instance, if we flatten out the data set, there are over 16,000 entries for user to role mappings. I'm looking for a way to aggregate the relationships into groups so that some manager can quickly validate and approve. So my first desire is to present groups of people who all have the same set of roles. There could be 30 people in the same 20 roles, so I want them to be able to scan two cells of a single row and say "yes" instead of 600 rows of data.

But .. some of those 30 could be in a different grouping with other people in a different set of roles. And the trick here would be that I wouldn't want to duplicate any of the 20 roles. But this is a next step and maybe needs to be handled by the application somehow. So let's just focus on the prior scenario.

Hi Doug,

We have a Cypher knowledge base article on performing MATCH intersection which covers the case you're after. Give that a try and see if that will work for you.