neo4j cypher nested collect

后端 未结 1 497
半阙折子戏
半阙折子戏 2021-02-06 00:56

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:30

    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)
提交回复
热议问题