neo4j find parent node is relationship exists

前端 未结 1 409
孤独总比滥情好
孤独总比滥情好 2021-01-26 11:45

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 w

相关标签:
1条回答
  • 2021-01-26 12:29

    [UPDATED]

    This query should return the group-accessible a directory that is closest to the root, starting at a specific (sub)directory:

    MATCH p=(g:group)-[:CAN_ACCESS_DIR]->(d:directory)<-[:CONTAINS*0..]-(a)
    WHERE g.name = "group1" AND d.name = "JAVA2"
    MATCH (a)<-[:CAN_ACCESS_DIR]-(g)
    RETURN p, a
    ORDER BY LENGTH(p) DESC
    LIMIT 1
    

    Since a single MATCH clause would filter out multiple uses of the same relationship, this query uses 2 MATCH clauses to allow the same CAN_ACCESS_DIR relationship to match twice, in case d is the only accessible directory (and therefore the same as a).

    0 讨论(0)
提交回复
热议问题