Cookies help us deliver our services. By using our services, you agree to our use of cookies. More information

Difference between revisions of "Neo4j:Reference - MATCH"

From NoSQLZoo
Jump to: navigation, search
(temp)
 
m (40166222 moved page Neo4j:Match to Neo4j:Reference: MATCH without leaving a redirect)
(No difference)

Revision as of 16:05, 15 October 2018

This tutorial uses NoSQLZoo data but is based on Cypher documentation, available here.

Get All Nodes

By just specifying a pattern with a single node and no labels, all nodes in the graph will be returned.

MATCH (n)
RETURN n;

Get All Nodes With a Label

Getting all nodes with a label on them is done with a single node pattern where the node has a label on it.
This query returns the names of all the gods in the graph.
Alternative syntax: MATCH (n) WHERE n:God RETURN n;

MATCH (n:God)
RETURN n.name;

Related Nodes

The Symbol -- means related to, without regard to type of direction of the relationship.

Return all direct (one jump) relations of Zeus.

MATCH (:God {name: "Zeus"})--(relative)
RETURN relative.name;

Match With Labels

To constrain your pattern with labels on nodes, you add it to your pattern nodes, using the label syntax.

Return all direct (one jump) relations of Zeus where the relative is a plain old Mortal.

MATCH (:God {name: "Zeus"})--(relative:Mortal)
RETURN relative.name;

Relationship Basics

When the direction of a relationship is of interest, it is shown by using --> or <--, like this:

Return all direct relations of Zeus where the relation is incoming.

MATCH (:God {name: "Zeus"})<--(relative)
// Same result: MATCH (relative)-->(:God {name: "Zeus"})
RETURN relative.name;