Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-27-2022 10:17 PM
Hello,
I only want to get/return paths between City (red) nodes, that go through Cable (blue) nodes and have property state:"working" Image here is only an example; path lengths between cities can be longer.
I mean something like this (not working):
MATCH p=(c1:City)-[*]-(c2:City) WHERE (x in nodes(p) WHERE x.state="working") RETURN p
This gives almost what I want:
match p=(c1:City {name:"Oslo"})-[*]-(c2:City {name:"Copenhagen"}) with nodes(p) as ns unwind [x in ns where x.state IS NOT NULL and x.state="working"] as ss return distinct(ss)
but I would like to get whole paths between to cities (with relationships).
02-28-2022 06:39 AM
Try this.
MATCH p=(c1:City)-[*]-(c2:City)
with p, [x in nodes(p) where x:Cable] as cableNodes
WHERE all (x in cableNodes WHERE x.state="working")
and c1<>c2
RETURN p
Note, you will probably get all kinds of unexpected paths because your pattern is not very restricted. For instance, in your example, you could get paths that traverse the c1 and c2 nodes multiple times, form loops, and terminate on the same starting node (I added a constraint against that in the query). The only restriction will be that a path will not traverse the same relationship twice.
All the sessions of the conference are now available online