I have a Neo4j database with many disconnected subgraphs (by design). Each subgraph has a "organization" node as it's root/start node. The intention is to have each organization only be able to query their own subgraph.
I have a webapp in front of the graph that provides the ID of the organization the user is part of. All nodes for the organization has a relationship with the organization node.
What is the best way to enforce query on a specific subgraph if you know the root/start node?
I have been playing with this example and it works but I would like to know if there is a better way of doing this:
MATCH (org:Organization {org_id: 1}) WITH org
MATCH p=(user:User)-[:SITTING_IN]->(room:Room)
WITH p, user, room
WHERE (user)-[:MEMBER_OF]->(org) AND (room)-[:MEMBER_OF]->(org)
RETURN p
This can quickly become cumbersome when the number of nodes grows with more complicated queries, and you have to remember to check them all in the WHERE clause..