I'm new to Neo4j and I'm working on poc where there are multiple services that can read and write to each other and modeled with <CAN_READ(INCOMING):CAN_WRITE(OUTGOING)> directed relationships as shown in the image below. I want to find all paths from A to F through compute services which can read from A and write to Service F and compute service should also able to write data to Service D. So the query should able to return paths highlighted in green and purple.
I have tried the below query which is giving Compute Services B,C and Storage Service A and Database Service F but Service D is not part of result path
What I'm trying to achieve is, I'm trying to find the services that can read from a service and write to multiple other services with the same relations
Query : MATCH p= (m:Service WHERE m.name = "A")-[r1:CAN_READ]->(n:Service)-[r2:CAN_WRITE]->(o:Service WHERE o.name = "F"),(n)-[r3:CAN_WRITE]->(t:Service WHERE t.name = "D") RETURN p
Result Output Paths: (A)<-[:CAN_READ]-(B)-[:WRITE_TO]->(F), (A)<-[:CAN_READ]-(C)-[:WRITE_TO]->(F)
How to get the node D also part of output path? Will i able to get the node D as part of output or it will be omitted as it not part of the primary MATCH path ? Do I need to use any other functions or features of neo4j to achieve the same
You can get the node D included in your output by also including it in your return statement.
MATCH p= (m:Service WHERE m.name = "A")-[r1:CAN_READ]->(n:Service)-[r2:CAN_WRITE]->(o:Service WHERE o.name = "F"),(n)-[r3:CAN_WRITE]->(t:Service WHERE t.name = "D") RETURN p, t
It seems to me that you are not really looking for a path, since you are defining all the endpoints and the length is only one hop. Instead it seems you are trying to answer the question as to which nodes can 1) read from A, 2) write to D, and 3) write to F. I may approach this question differently.
MATCH (a:Service WHERE a.name = "A")
MATCH (f:Service WHERE f.name = "F")
MATCH (d:Service WHERE d.name = "D")
MATCH (a)-[r1:CAN_READ]->(n:Service)
WHERE exists( (n)-[r2:CAN_WRITE]->(f) )
and exists( (n)-[r3:CAN_WRITE]->(d))
RETURN a, f, d, n
The above doesn’t return the relationships. Do you need these too?
@glilienfield THANKS FOR YOUR RESPONSE. Yes, I required those relationships as part of output
The below query is giving the correct result as expected, but the result is coming in 2 different columns. Is there any way we can combine the results into single column with "," separated paths
MATCH p= (m:Service WHERE m.name = "A")-[r1:CAN_READ]->(n:Service)-[r2:CAN_WRITE]->(o:Service WHERE o.name = "F"),(n)-[r3:CAN_WRITE]->(t:Service WHERE t.name = "D") RETURN p, t
you can't concatenate the nodes as a string. You could create a list of the nodes as a column and a list of the relationships as a second column. If you want just one column you could return a map with all the entities.