I'm doing the exercises from the Intermediate Cypher Queries- Pipelining queries and in the Unique Genres one I was asked to get something like a set of values from a specific dictionary "Key" (at least I would see it like this if I was working on Python).
The Query from the solution is the following:
MATCH (n:Movie)
WHERE n.imdbRating IS NOT NULL AND n.poster IS NOT NULL
WITH n {
.title,
.imdbRating,
actors: [ (n)<-[:ACTED_IN]-(p) | p { tmdbId:p.imdbId, .name } ],
genres: [ (n)-[:IN_GENRE]->(g) | g {.name}]
}
ORDER BY n.imdbRating DESC
LIMIT 4
RETURN collect(n)
I understand the questions expects me to "manually" keep track of the Genres result and count them in order to answer the exercise.
Do you know a way to make something like
RETURN apoc.coll.toSet[collect(n.genres[i].name) for i range(0, size(collect(n))) ]?
My idea was to iterate over all elements in my collection(n), getting the value (a list in this case) from the "genres" key, making a set of these, then make another collection, and just then applying one last transformation to this list in order to convert its entries to a set.