Database Reference
In-Depth Information
node of the relationship is connected using the single hyphen character ( []- ). In the pre-
ceding example, the match (user)-[:HAS_SEEN]->(movie) pattern specifies the
HAS_SEEN relationship from the user node toward the movie node.
Ifyoudon'tcareabouttherelationship direction, oryou'renotsurewhichisthestarting or
ending node of the relationship, you can use the single hyphen character on both sides, in
which case it reads as “any.” If you want to know if two users are friends, regardless of the
direction, the following pattern can be used:
start user1=node(1)
match (user1)-[:IS_FRIEND_OF]-(user2)
return user2;
Let's now take a look at how the node and relationship identifiers are used in Cypher.
Using node and relationship identifiers
Both nodes and relationships in Cypher queries can be associated with identifiers, which
are used to reference the same graph entity later in the same query. In the following ex-
ample, the node named movie has been referenced in the return clause.
Relationships can be named as well, using slightly different syntax:
To give a name to a relationship, simply specify the name you want to give it within the
square brackets, before the relationship type.
Naming nodes and relationships can be very useful when creating complex patterns, be-
cause you can reference them later in other parts of a Cypher query. But if you don't need
to reference the graph entity later, avoiding identifiers will make your query easier to read
and understand.
In the preceding example, the nodes in the pattern were named ( user is the starting node
and movie is the node you want to return from the query), but not the relationship, be-
causetherewasnoplantoreferenceitanywhereelse.Tomaketherelationshipanonymous,
Search WWH ::




Custom Search