Weekly Challenge #3 Lots of directors

Create a recommendations sandbox at sandbox.neo4j.com.

For this dataset, write a query that returns one row for every movie in the graph that has at least 10 directors.

It will also return the list of reviewers for each movie.

Each row will contain:

  • Movie (title of the movie)
  • DIrectors (list of the names of the directors for that movie)
  • Reviewers (list of the names of the reviewers of that movie)

Great job @Cobra

Hello @TrevorS :blush:

Here is the query:

MATCH (m:Movie) 
WHERE size((m)<-[:DIRECTED]-()) >= 10 
RETURN m.title AS title, [(m)<-[:DIRECTED]-(d) | d.name] AS directors, [(m)<-[:RATED]-(u) | u.name] AS reviewers;

Here is the screenshot:

Weekly Challenge #3.png

Regards,
Cobra

These all are the same idea.

match (m:Movie)<-[:DIRECTED]-(p)
with m, count(p) as count
where count > 9
match (m)<-[:DIRECTED]-(p)
with m, collect(p.name) as directors
match (m)<-[:RATED]-(u)
return m.title as title, directors, collect(u.name) as reviewers

Is it any better?

Hello @TrevorS,

MATCH (n:Movie)
WHERE size((n)<-[:DIRECTED]-()) >= 10
WITH n { .title,
directors: [ (n)<-[:DIRECTED]-(p) | p.name],
reviewers: [ (n)<-[:RATED]-(g) | g.name]
}
RETURN n.title AS title, n.directors AS directors, n.reviewers AS reviewers

I've just started learning Neo4j and I'm currently completing the Intermediate Cypher Queries course when I saw the challenge and decided to share this.

loois_0-1660749661176.png

Regards,

L

Hello @loois ,

Your query performs just as well as the query from @Cobra . Both are great solutions.

Good luck on your Cypher learning journey @loois