cancel
Showing results for 
Search instead for 
Did you mean: 

Possible Bug in Exercise 7.1: Collect and use lists (Solution)

janvictor
Node Link

Dear Neo4j community,

I'm new to Neo4j so i don't know if my observation is correct, but i believe that the example code of the solution page in exercise 7.1 is bugged. The introduction text states:

Write a Cypher query that retrieves all actors that acted in movies, and also retrieves the producers for those movies. During the query, collect the names of the actors and the names of the producers. Return the movie titles, along with the list of actors for each movie, and the list of producers for each movie making sure there is no duplication of data. Order the results returned based upon the size of the list of actors.

The focus here beeing:

no duplication of data

Moreover, the exercise demands ordering the results

based upon the size of the list of actors

The proposed Cypher statement on the solution page is:

MATCH (a:Person)-[:ACTED_IN]->(m:Movie),
      (m)<-[:PRODUCED]-(p:Person)
WITH  m, collect(a.name) AS cast, collect(DISTINCT p.name) AS producers
RETURN DISTINCT m.title, cast, producers
ORDER BY size(cast)

The result of this statement returns distinct titles but appends the list of actors times count of producers.

What worked for me was this statement:

MATCH (a1:Person)-[:ACTED_IN]->(m:Movie),
	(a2:Person)-[:PRODUCED]->(m)
WITH m.title AS Title, collect(DISTINCT a1.name) AS Cast, collect(DISTINCT a2.name) AS Producers
RETURN Title, Cast, Producers
ORDER BY size(Cast) DESC

with the following result:

Some of the previous exercises had progressive statement modifications where the statement was modified step by step to reach a certain goal. As it is not the case here i suspect a bug.

Is this correct?
Thank you for your time.

1 ACCEPTED SOLUTION

Hello Jan,

There should definitely be the DISTINCT qualifier for the actor names. We will fix it in the course.

Thanks for picking up on it.

Elaine

View solution in original post

1 REPLY 1

Hello Jan,

There should definitely be the DISTINCT qualifier for the actor names. We will fix it in the course.

Thanks for picking up on it.

Elaine

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.