Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-21-2021 09:50 AM
Hi guys! The question is how to get all nodes in path between start and end note
match p=((s:Group{id:10})-[:CHILD*]->(f:Group{id:1})) return p
how exclude nodes with id 10 and id 1 from the result?
10-21-2021 12:16 PM
This is my data.
CREATE (s:Group{id:10})-[:CHILD]->(:Group{id:2})-[:CHILD]->(:Group{id:3})-[:CHILD]->(f:Group{id:1}),
(s)-[:CHILD]->(:Group{id:4})-[:CHILD]->(:Group{id:5})-[:CHILD]->(f),
(s)-[:CHILD]->(:Group{id:6})-[:CHILD]->(f)
I create the Cypher.
It works, but it's not cool.
MATCH p=((s:Group{id:10})-[:CHILD*]->(f:Group{id:1}))
WITH nodes(p) AS nodes
UNWIND nodes AS node
WITH collect(distinct(node.id)) AS allNodeIds
MATCH (g:Group)
WHERE g.id IN allNodeIds
AND NOT g.id IN [10,1]
RETURN g
10-21-2021 01:36 PM
Thank you so much, I will try to reuse your solution for my task
10-21-2021 01:44 PM
Based on @koji solution I may just add one modification in order to avoid some 'branching' on the profile of the query.
explain MATCH p=((s:Group{id:10})-[:CHILD*]->(f:Group{id:1}))
WITH nodes(p) AS nodes
UNWIND nodes AS node
with node where NOT node.id IN [10,1]
RETURN node
Bennu
PS : let us know if APOC is an option for you as well.
10-21-2021 02:05 PM
Wow, thanks. This query is way understandable. I just started to use neo4j, and I looking for query I able to understand
All the sessions of the conference are now available online