问题
I am trying to develop a product like a google drive. This is the second phase now. I am stuck in making cypher query and I need help.
a user A can share a file/folder with a group or another user B.
case 1: user A, shared the folder which consists of other subfolders. user B would see the shared folder. however, now user A shared a subfolder, and again user B should see only the root folder.
case 2: user A, shared the only subfolder then, user B will only see a shared subfolder
basically I need to traverse the node from bottom to its parent and their parent with CAN_ACCESS_DIR relationship if any and stop at the first node with this relationship
please help
attached image scenario -> find the root (JAVA) of JAVA2 and check if it has been shared (CAN_ACCESS_DIR) with the same group or a user. If yes, then we will send only the JAVA folder. If not then send only JAVA2 folder
match (g:group) where g.name = "group1"
match p = (d:directory { name: "JAVA2"})<-[:LEAF | CONTAINS*0..]-(a:directory) where (d)<-[:CAN_ACCESS_DIR]-(g)
unwind nodes(p) as i
return collect(distinct(i)) as result
match (u:user) where u.name = "John"
match (t:tower) where t.name = "Genome"
match (d:directory) where d.name = "Root"
match (u)-[:MEMBER_OF_GROUP]->(g:group)
match (d)-[:CONTAINS*0..]->(s) where (s)<-[:CAN_ACCESS_DIR]-(g)<-[:MEMBER_OF_GROUP]-(u)
not an expert in neo4j, please guide me out. thanks
回答1:
This query should return the group-accessible a
directory that is closest to the root:
MATCH p=(g:group)-[:CAN_ACCESS_DIR]->(d:directory)<-[:CONTAINS*0..]-(a)<-[:CAN_ACCESS_DIR]-(g)
WHERE g.name = "group1" AND d.name = "JAVA2"
RETURN p, a
ORDER BY LENGTH(p) DESC
LIMIT 1
来源:https://stackoverflow.com/questions/62220884/neo4j-find-parent-node-is-relationship-exists