neo4j cypher nested collect

后端 未结 1 557
花落未央
花落未央 2021-02-06 01:01

Imagine a photo album schema w/ Users, Albums, and Photos:

User -[owns]-> Album -[contains]-> Photo

Can I do a nested collect to get Phot

1条回答
  •  不知归路
    2021-02-06 01:26

    Try this query:

    MATCH (a:USER)-[:owns]->(b:ALBUM)-[:CONTAINS]->(c:PHOTO)
    WITH a,b,{url: c.name} as c_photos
    WITH a,{album: b.name , photos: collect(c_photos)} as b_albums
    WITH {name: a.name, albums: collect(b_albums)} as a_users
    RETURN {users: collect(a_users)}
    

    Edit

    To get all properties of a node you can use string representation of the node and then parse it separately using java etc

    MATCH (a:User)
    WITH {user: str(a)} as users
    RETURN {users: collect(users)}
    

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