Neo4j cypher nested collection

Introduce the w / Users, Albums and Photos photo album diagram:

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

Can I make a nested fee to get photos and albums nested in albums nested in User? I will like results similar to:

 { "users": [ { "name": "roger dodger", "albums": [ { "album": "album1", "photos": [ {"url": "photo1.jpg"}, {"url": "photo2.jpg"} ] } ] } ] } 

This seems close, but I could not change it to fit my needs: Has_many nested relationships in cypher (Could the problem be that the neo4j 2.0 web console does not support json syntax in this example?)

+6
source share
1 answer

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 the properties of a node, you can use the 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)} 
+19
source

All Articles