cancel
Showing results for 
Search instead for 
Did you mean: 

Exercise 5.12 solution

anystack100
Node Link

Hi all,
Just checking whether my solution for exercise 5.12 would be considered equivalent to the solution the course provided?

My solution:

MATCH (m:Movie)<-[:DIRECTED]-(d:Person)
WITH count(d) AS numDirectors, m
WHERE numDirectors >= 2
OPTIONAL MATCH (m)<-[:REVIEWED]-(r:Person)
RETURN m.title, r.name

Provided solution:

MATCH (m:Movie)
WITH m, size((:Person)-[:DIRECTED]->(m)) AS directors
WHERE directors >= 2
OPTIONAL MATCH (p:Person)-[:REVIEWED]->(m)
RETURN  m.title, p.name

The returned data was the same:


Cheers,
Scott

2 REPLIES 2

llpree
Graph Buddy

Yes. They get the same results. I'd argue that your solution is more optimal. Looking at PROFILE and checking the performance, it's about twice as fast, albeit for a small database, and the PROFILE seems to points at the reasons for that - the initial query optimizes the path for a more constrained request. I found in various examples, the goal of their solutions were often to show neat ideas to keep in mind rather than "best practice". Keep it up!

Thanks for the feedback! Yeah, I think I've noticed it's not all supposed to be best practice although I wasn't aiming for better performance with this - just what came to mind first.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.