Database Reference
In-Depth Information
Optional Match
The OPTIONAL MATCH (Listing 4-27), which is a new clause in Neo4j 2.0, allows Cypher to match patterns against
your graph database, but the primary difference is that if no matches are found, NULLs will be returned for any
missing parts of the pattern. It is analogous to an outer join in SQL. In prior releases of Neo4j, a question mark was
supplied next to the relationship type.
Listing 4-27. OPTIONAL MATCH
MATCH (u1:User {username: "greg"} )
OPTIONAL MATCH (u1)-[f:FOLLOWS]->(u2)
RETURN f
Where
WHERE is always used in conjunction with another clause, such as MATCH, WITH and/or START.
Listings 4-28 through 4-32 exemplify the use of WHERE to filter on results with MATCH.
Listing 4-28. MATCH Where a Property Has a Certain Value
MATCH (u:User)
WHERE u.active = true
RETURN u
Listing 4-29. MATCH Where a Property Has a regex Match
MATCH (u:User)
WHERE u.username = "gre.*"
RETURN u
Listing 4-30. MATCH Using a Property regex Case-Insensitive Match
MATCH (u:User)
WHERE u. username = "(?i)GRE.*"
RETURN u
Listing 4-31. MATCH Where a Property Matches a Value in a Collection
MATCH (u:User)
WHERE u. username IN ["greg","jeremy"]
RETURN u
Listing 4-32. MATCH Using a Property regex Case-Insensitive Match
MATCH (u:User {username: "greg"} )
WHERE NOT (f)-[:FOLLOWS]-(u)
RETURN f
 
Search WWH ::




Custom Search