Skip to content

Instantly share code, notes, and snippets.

@cskardon
Last active October 30, 2024 14:24
Show Gist options
  • Save cskardon/341729d707a7e1da3653ccfd43702ec2 to your computer and use it in GitHub Desktop.
Save cskardon/341729d707a7e1da3653ccfd43702ec2 to your computer and use it in GitHub Desktop.
A gist of the projection queries used in the Advanced Neo4j course
MATCH (actor:Person)-[:ACTED_IN]->(m:Movie)<-[:ACTED_IN]-(coactor:Person)
WHERE actor.name = "Tom Hanks" AND actor <> coactor
WITH
actor.name AS actor,
m.title AS title,
coactor.name AS movieCoactors
RETURN
actor, title, movieCoactors
//002
MATCH (actor:Person)-[:ACTED_IN]->(m:Movie)<-[:ACTED_IN]-(coactor:Person)
WHERE actor.name = "Tom Hanks" AND actor <> coactor
WITH
actor.name AS actor,
m.title AS title,
collect (coactor.name) AS movieCoactors
RETURN
actor,
title,
movieCoactors
//003
RETURN {first: 'Tilly', last: 'Itten'} AS name
//004
WITH {first: 'Tilly', last: 'Itten'} AS name
RETURN name.first + name.last AS fullname
//005
MATCH (actor:Person)-[:ACTED_IN]->(m:Movie)<-[:ACTED_IN]-(coactor:Person)
WHERE actor.name = "Tom Hanks" AND actor <> coactor
WITH
actor,
m.title AS title,
collect (distinct coactor.name) AS movieCoactors
RETURN
actor,
{Movie: title, MovieCoactors: movieCoactors} AS projection
//006
MATCH (actor:Person)-[:ACTED_IN]->(m:Movie)<-[:ACTED_IN]-(coactor:Person)
WHERE actor.name = 'Tom Hanks' AND actor <> coactor
WITH
actor.name AS actor,
m.title AS title,
collect (distinct coactor.name) AS movieCoactors
WITH actor,
{Movie: title, MovieCoactors: movieCoactors} AS projection
RETURN
actor,
COLLECT(projection) AS projection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment