Database Reference
In-Depth Information
The smart bit comes in the
where
clause . You use the
NODES(p)
Cypher function
to extract the collection of all nodes in the given path. You check that each node has the
facebookId
property by using the
HAS
function. Then you use the
ALL
function to ap-
ply the
HAS
predicate to every element of the collection of nodes. The function
ALL
will
return
true
if every element in the given iterable matches the predicate, so if one of the
nodes on the path
p
doesn't have a
facebookId
property, the path will be discarded.
Finally, you return the paths that fulfill all criteria . The path will contain all people
John will need to contact so he can be introduced to Kate on Facebook.
You've seen quite a few functions in action in this example:
•
HAS(graphEntity.propertyName)
—Returns
true
if the property with a given
name exists on a node or relationship.
•
NODES(path)
—Transforms a path into an iterable collection of nodes.
•
ALL(x in collection where predicate(x))
—Returns
true
if every single element
of
collection
matches the given
predicate
.
Neo4j supports a lot more functions with similar purposes to the ones we described here.
For example, like the
NODES(path)
function, the
RELATIONSHIPS(path)
function
returns a collection of all relationships on the given path.
In addition to
ALL
, Neo4j supports other predicate-based Boolean functions:
•
NONE(x in collection where predicate(x))
—Returns
true
if no elements of the
supplied collection match the predicate; otherwise it returns
false
.
•
ANY(x in collection where predicate(x))
—Returns
true
if at least one element
matches the predicate; if none matches, it returns
false
.
•
SINGLE(x in collection where predicate(x))
—Returns
true
if exactly one ele-
ment of the collection matches the predicate; if no elements or more than one ele-
ment matches, this function returns
false
.