Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-24-2022 09:14 AM
I wonder if there is a more elegant way to find nodes which are not linked to other specific nodes.
Model:
nodes in darker green are "regions"
nodes in lighter green are "countries"
there can be a mix of children, with both "regions" and "countries"
all relationships are of the same type ("rel")
I would like to extract the end region nodes (those regions) which only contain countries underneath, and I thought to be a no-brainer...silly me.
Eventually, this worked, but i do not like it:
match (w:Region{Code:'R1'})
with w optional match (w)-[r]->(i:Region)
with w, collect(r.acr) as p where size(p)=0
return w.Code
Note:r.acr is just some random property which i have been using with collect
I was expecting something like "optional match (e:Region) where not( (e)--(e1:Region) )but as e1 needs to be declared prior to "where", it creates a cartesian product in which, of course, if finds some regions which are not directly linked.
Also tried the count directly in where
02-24-2022 10:15 AM
Try:
match (w:Region{Code:'R1'})
optional match (w)-->(i:Region)
with w, count(i) as cnt
where cnt = 0
return w.Code
Or
match (e:Region{Code:'R1'})
where not exists( (e)-->(:Region ) )
return e.Code
All the sessions of the conference are now available online