Lets say, we have a database with (:TvShow)-[:contain]->(:Season)-[:contain]->(:Episode)
Now lets say, one wants to query the database for a specific :TvShow and get a result shaped this way : {tvshow : //The tvShow node// , seasons: [ {season: //Season node// , episodes: [//episode node//]}]}
For exemple: if we have OneShow with 2 seasons and 3episodes
the result would be a json object: {tvshow: OneShow, seasons: [{season: Season1, [episode1-1,episode1-2,episode1-3]},{season: Season1, [episode2-1,episode2-2,episode2-3]}]}
I'm trying to work with WITH, collect, FOREACH and the array operator '+' but without success yet.
Anyone has done this before?
Based on the following Neo4j console dataset http://console.neo4j.org/r/7uru0d, you can achieve it in this way :
MATCH (n:TvShow)-[:HAS_SEASON]->(season)-[:HAS_EPISODE]->(episode)
WITH n, season, collect(episode) AS ep
RETURN { show: n.id, seasons:collect({ season: season.name, episodes: ep })} AS shows
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With