Reputation: 12044
I'm reading about relationships and how I can obtain the relations of each individual node.
Just now, I have a node A
with relation [:MATCH] with a node B
, also I have the nodeC
and the node D
.
I could have more node relations with [:MATCH] in other nodes.
How I can obtain only relations of an specific node?
Upvotes: 0
Views: 361
Reputation: 12044
To see an specific relation you can use:
MATCH (p:Person)-[r:WORKS_FOR]->(c:Company)
WHERE p.name = "Bob"
RETURN r;
But, If you need see a Bidirectional relation, you can use:
MATCH (p:Person)-[r:WORKS_FOR]-(c:Person)
WHERE p.email= "[email protected]"
RETURN r;
When you can use it?, For example, if you have a friend you can say:
John is Friend of Mary, and Mary is John's Friend.
Add two relationships is a bad pattern in Neo4J, but you can use -
wihout the symbol >
to not specify direction of the relationship.
Upvotes: 0
Reputation: 8556
With Cypher you can bind variables to relationships in a pattern. For example:
MATCH (p:Person)-[r:WORKS_FOR]->(c:Company)
WHERE p.name = "Bob"
RETURN r;
Will bind any :WORKS_FOR
relationships to the variable r
for the Person node with name property "Bob".
Upvotes: 1