filipyoo
filipyoo

Reputation: 357

neo4j : MATCH when a node is connected to 3 nodes

I'm trying to model flights using the following model : flights model

So a flight is connected simultaneously to 3 nodes : Airport (with the FROM relationship), another Airport (with TO) and the day Node (with FLY_ON).

So, given that we can only write left and right relationships how would I write a Cypher query to give me a flight flying FROM airport A, TO airport B, flying on D day ? I would like to do something like :

    MATCH (a:Airport)<-[:FROM]-(f:Flight)-[:TO]->(b:Airport)
                                  |  
                              [:FLY_ON]->(d:Day)-[:IN_MONTH]->(m:Month)

I've tried to do this with 2 subsequent (first, retrive all flights flying on the given day in the given month), and using the WITH Clause, but it does also give me flights that don't fly on the specified day.

Thank you !

Upvotes: 0

Views: 609

Answers (1)

Tomaž Bratanič
Tomaž Bratanič

Reputation: 6514

Try something like this:

MATCH (a:Airport)<-[:FROM]-(f:Flight)-[:TO]->(b:Airport),
(f)-[:FLY_ON]->(d:Day)-[:IN_MONTH]->(m:Month)
RETURN ...

Upvotes: 2

Related Questions