Boolean operators with Cypher
Cypher supports the Boolean operators AND
, OR
, NOT
, and XOR
, which are very useful to describe more than one condition to be checked simultaneously. In this recipe, we will learn their uses within the graph we have created.
Getting ready
To step through this recipe, you will need to create the nodes and relationships for which data has been provided with the code files.
How to do it...
We have divided this recipe into the following problem sets:
- The Boolean operator AND with Cypher: Let's get all the flights that originate from any airport in
Atlanta
city that are destined forDallas/Fort Worth
:MATCH (o)<-[:`ORIGIN`]-(f)-[:`DESTINATION`]->(d) where o.city = "Atlanta" AND d.city = "Dallas/Fort Worth" return o,f,d
The following screenshot shows the Neo4j console depicting the result of the
AND
Boolean query: - The Boolean operator OR with Cypher: Let's get all the flights that originate from either from
Atlanta
orDallas/Fort Worth
...