In this bankruptcy, we are able to find out about Match Clause and all the functions that may be completed the use of this clause.
Get All Nodes Using Match
Using the MATCH clause of Neo4j you can retrieve all nodes within the Neo4j database.
Example
Before proceeding with the example, create three nodes and a couple of relationships as shown under.
CREATE (Dhoni:player {name: "MahendraSingh Dhoni", YOB: 1981, POB: "Ranchi"})
CREATE (Ind:Country {name: "India", result: "Winners"})
CREATE (CT2013:Tornament {name: "ICC Champions Trophy 2013"})
CREATE (Ind)-[r1:WINNERS_OF {NRR:0.938 ,pts:6}]->(CT2013)
CREATE(Dhoni)-[r2:CAPTAIN_OF]->(Ind)
CREATE (Dhawan:player{name: "shikar Dhawan", YOB: 1995, POB: "Delhi"})
CREATE (Jadeja:player {name: "Ravindra Jadeja", YOB: 1988, POB: "NavagamGhed"})
CREATE (Dhawan)-[:TOP_SCORER_OF {Runs:363}]->(Ind)
CREATE (Jadeja)-[:HIGHEST_WICKET_TAKER_OF {Wickets:12}]->(Ind)
Following is the query which returns all the nodes in Neo4j database.
MATCH (n) RETURN n
To execute the above question, carry out the following steps −
Step 1 − Open the Neo4j desktop App and start the Neo4j Server. Open the integrated browser app of Neo4j the use of the URL http://localhost:7474/ as shown inside the following screenshot.
Step 2 − Copy and paste the desired question in the dollar activate and press the play button (to execute the query) highlighted inside the following screenshot.
Result
On executing, you'll get the subsequent end result.
Getting All Nodes Under a Specific Label
Using healthy clause, you could get all of the nodes beneath a selected label.
Syntax
Following is the syntax to get all of the nodes underneath a selected label.
MATCH (node:label)
RETURN node
Example
Following is a pattern Cypher Query, which returns all of the nodes within the database underneath the label player.
MATCH (n:player)
RETURN n
To execute the above question, carry out the subsequent steps −
Step 1 − Open the Neo4j computer App and begin the Neo4j Server. Open the built-in browser app of Neo4j the usage of the URL http://localhost:7474/ as proven within the following screenshot.
Step 2 − Copy and paste the favored question in the dollar set off and press the play button (to execute the query) highlighted within the following screenshot.
Result
On executing, you may get the subsequent end result.
Match by Relationship
You can retrieve nodes based on relationship using the MATCH clause.
Syntax
Following is the syntax of retrieving nodes based totally on the connection the usage of the MATCH clause.
MATCH (node:label)<-[: Relationship]-(n)
RETURN n
Example
Following is a sample Cypher Query to retrieve nodes based on relationship the use of the MATCH clause.
MATCH (Ind:Country {name: "India", result: "Winners"})<-[: TOP_SCORER_OF]-(n)
RETURN n.name
To execute the above question, perform the subsequent steps −
Step 1 − Open the Neo4j computing device App and start the Neo4j Server. Open the built-in browser app of Neo4j the use of the URL http://localhost:7474/ as shown within the following screenshot.
Step 2 − Copy and paste the preferred query in the dollar set off and press the play button (to execute the query) highlighted within the following screenshot.
Result
On executing, you may get the subsequent result.
Delete All Nodes
You can delete all of the nodes using the MATCH clause.
Query
Following is the question to delete all of the nodes in Neo4j.
MATCH (n) detach delete n
To execute the above question, perform the following steps −
Step 1 − Open the Neo4j laptop App and start the Neo4j Server. Open the built-in browser app of Neo4j the use of the URL http://localhost:7474/ as shown within the following screenshot.
Step 2 − Copy and paste the favored query within the greenback spark off and press the play button (to execute the question) highlighted in the following screenshot.
Result
On executing, you may get the subsequent result.