Querying the data model to find what is accessible to an employee

To find which hotels are accessible to an employee, we can traverse the :CAN_ACCESS relationships. The following query gets all the hotels accessible to an employee via all the groups the employee has access to, and also returns all the airports and locations of the hotels to which the employee has access:

MATCH p = (chain:HotelChain)<-[:EMPLOYED_BY]-(employee:Employee{_id:17812})-[:MEMBER_OF]->(:AccessGroup)-[:CAN_ACCESS*0..]->(hotel:Hotel)-[:BELONGS_TO]->(hotelChain:HotelChain)
WITH p, hotel
MATCH (hotel)<-[:HAS_HOTEL]-(airport:Airport)<-[:HAS_AIRPORT]-(city:City)
RETURN p, hotel, airport, city

The output of the preceding query is as follows:

Figure 7.15: Hotels accessible to members ...

Get Neo4j Graph Data Modeling now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.