neo4j
Get all related nodes of a node using Cypher query neo4j
The Cypher query can be used to get all related nodes of a node. The query will return all the nodes that are related to a node in a neo4j graph DB.
MATCH (Person {name: 'Lana Wachowski'})--(movie)
RETURN movie
Using the above query, we are getting all nodes that are related to the node that has the name value 'Lana Wachowski'. The query will return all the nodes either is a movie label node or person label node if they are related to the node that has a name-value as Lana Wachowski.
MATCH (Person)--(movie)
RETURN movie
This will return all nodes that have Person labels and the related nodes of those(e.g. all the movies related to the Person).
MATCH (p:Person)--(m)
WHERE ID(p) = 3
RETURN m
In the above Cypher query, we are getting related nodes of a Person label node that has an id 3.
//Get all nodes
MATCH (:Person {name: 'J.T. Walsh'})--(m:Movie)
RETURN m
//Get title only
MATCH (:Person {name: 'J.T. Walsh'})--(m:Movie)
RETURN m.title
The Cypher query can be used to get all related nodes that are labeled with some text. Here, we are getting all related nodes labeled as Movies to the node labeled as Person and has name value as J.T. Walsh.
Was this helpful?
Similar Posts
- Get all nodes with same label using label name Cypher query neo4j
- Get all nodes cypher query neo4j
- Get node using id Cypher query neo4j
- Get nodes using multiple ids Cypher query neo4j
- Get the type of relationship variables of a node Cypher query neo4j
- Delete nodes using Cypher query neo4j
- Delete node relationship only Cypher query neo4j