How can I get all paths to node?

In theory, there might be a situation in which the loop is longer. For example, ["L1", "S21", "L21", "S22", "L22", "S23", "L23", "S24", "L1"].
The student may have skill S22 (obtained through another lesson L99), so he should be able to follow route ["L99", "S22", "L22", "S23", "L23", "S24", "L1"] to the required lesson (the skill that this lesson provides). And we are depriving him of this opportunity.

PS: I understand that it looks strange. But people sometimes do illogical things. Even teachers creating lessons.

Well,

I don't have L99 on my DB so It's hard too see this scenario on my mind. Nothing a good functional requirement can't solve :stuck_out_tongue:

B

match (a:Lesson)-[:REQUIRES]->(b:Skill)
with distinct a.id as lesson, collect(distinct b.id) as skls

match (c:Skill)-[:PROVIDED_BY]->(d:Lesson)
where c.id in skls
with lesson, skls, collect(distinct d.id) as lessons 
return lesson as Lesson, apoc.coll.sort(skls) as requiredSkills, apoc.coll.sort(lessons) as lessonsProvideSkills, size(lessons) as totalLessons order by totalLessons desc

Result:

This is a very interesting use case! :slight_smile: Great way to get to learn neo4j!!! ;-)