Querying nodes and relationships using Cypher
Cypher can be used to query nodes and relationships based on properties, relation types, labels, and so on. You can also write complex Cypher queries to query a subpart of the graph. In this recipe, we will learn some commonly used Cypher queries, which will be useful for querying the graph.
Getting ready
To step through this recipe, you will need to create some nodes and relationships among them to get the most from this recipe.
How to do it...
We have divided this recipe into the following problem sets:
Counting all nodes that exist in the graph:
START n = node(*) RETURN COUNT(n)
Counting all relationships that exist in the graph:
MATCH (n)-[r]-(m) RETURN COUNT(r)
Finding all distinct labels that exist in the graph:
MATCH (n) RETURN DISTINCT LABELS(n)
Finding all distinct relationship types that exist in the graph:
MATCH n-[r]-() RETURN DISTINCT TYPE(r)
Finding all nodes that are disjoint, which means that they do not have any relationship with the other...