cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Filter nodes based on relationships property and if property does not exist return all the nodes

Hi, I have four nodes Order, Service, Brand, Slot. Brand has Slots and Services. Orders are created according to Slots available for a particular Service. I wanted to run query to check if an Slot exits for a Service and to do that I have to query the Orders to check if Slot is already booked or not for that service, if booked I want to return all the other slots and if not booked I want to return all the slots available for that service. How should I modify this query

MATCH (brand :Brand {id: "1"}) MATCH (slot:Slot)-[:HAS_SLOT]-(brand) MATCH (slot)-[appointment:HAS_APPOINTMENT]-(order:Order) WHERE appointment.serviceId <> "2" AND appointment.date <> DateTime("2011-10-05T14:48:00Z") RETURN slot

1 REPLY 1

krisgeus
Node Clone

Can you use this? https://neo4j.com/docs/cypher-manual/current/clauses/where/#property-existence-checking

where clause would become someting like this:

WHERE (NOT exists(appointment.serviceId) AND NOT exists(appointment.date)) OR (appointment.serviceId <> "2" AND appointment.date <> DateTime("2011-10-05T14:48:00Z"))

Not tested so syntax might differ slightly