Search code snippets, questions, articles... Chrome Extension

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
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

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?
0 Comments
Join Devsheet Ask a Question