cancel
Showing results for 
Search instead for 
Did you mean: 

Intro to Neo4j 4.0 - Exercises 7.4 and 7.5

begloria_c3
Node Link

A couple questions for general understanding, noting that I am writing queries before moving to the exercise answers... 7.4 - The given solution actually returns nodes and you have to switch to table view to get the list of data. I'm not really clear on when the exercises want a list vs. when they want a node. Is there some tip, something I should be looking for, to let me know which direction to take? 7.5 - The solution is given as:

MATCH (p:Person)-[:ACTED_IN]->(m:Movie)
WITH p, collect(m) AS movies
WHERE size(movies) > 5
WITH p, movies UNWIND movies AS movie
RETURN p.name, movie.title

I don't really understand why "movies" precedes "UNWIND movies AS movie" - why is it not simply "UNWIND movies AS movie" by itself? Please explain.

3 REPLIES 3

Hello,

The WITH clause is used to pass variables to subsequent parts of the query.

After the WHERE clause, the query is done and what you have to work with is p, m, and movies for the next part of the query. We use WITH to pass p and movies to the next part of the query where we return data. If you were to take movies out of the second WITH clause, you would not have access to the values stored in movies. This exercise shows you how to pass variables along in the query process.

In general, if the query returns nodes or paths, you typically look at it in Neo4j Browser as a graph, but there is nothing that would prevent you from viewing the data as a table. Of course if you return property values, then you no longer have the graph view available and you must view the data as a table.

Elaine

begloria_c3
Node Link

Ok, so if I understand you correctly, I've inserted a simple CRLF at the place that was causing confusion, below. It wasn't with the use of the WITH clause itself - I get that it is used to forward interim results to the rest of the query. It was that I was reading the UNWIND statement as being part of the WITH statement, instead of (effectively) its own statement. The presentation of the material, in other words, is what was causing confusion. Adding a CRLF makes it clearer, based on my perception.

MATCH (p:Person)-[:ACTED_IN]->(m:Movie)
WITH p, collect(m) AS movies
WHERE size(movies) > 5
WITH p, movies
UNWIND movies AS movie
RETURN p.name, movie.title

Regarding nodes vs. table, I think you misunderstood my question. What I am looking for regards only what is being requested within the tutorial itself, not what can happen in the world outside of the tutorial. It is not always clear to me from the tutorial wording when the tutorial wants a graph returned vs when the tutorial wants property values returned. Particularly after multiple exercises that focus on property values, throwing an exercise into the mix that looks for a graph to be returned, without somehow stating that the result should come as a graph, seems like it's coming from out in left field - we've been asking for property values but, surprise!, we want a graph here!

If I were to sit down and take the Neo4j certification exam right now, would some of the questions be unclear in this manner and, hence, could my response be considered incorrect when it was actually correct from a property value perspective? How can I always know if a question wants property values or a graph?

We will try to make the instructions clearer going forward.

You should not be confused by how results are viewed in Neo4j Browser when you take the certification exam. It is good that you are seeing the differences in how data can be returned and how it can be displayed in the UI of Neo4j Browser.

Elaine