Querying
This page shows you how to create the following simple Cypher® query to MATCH and RETURN movies using the Cypher Builder:
MATCH(m:Movie)
RETURN m
Instructions
-
Define a node variable by creating a new instance of
Cypher®.Node:const movieNode = new Cypher.Node(); -
Create the pattern to be matched against with
Cypher®.Pattern:const matchPattern = new Cypher.Pattern(movieNode, { labels: ["Movie"] }); -
Create a
MATCHclause and pass the pattern as an argument:const clause = new Cypher.Match(matchPattern); -
To
RETURNthe node variables, use the.returnmethod in theMATCHclause:clause.return(movieNode);-
Alternatively, you can do the same by creating the clause with a single statement:
const clause = new Cypher.Match(matchPattern).return(movieNode);
-
-
After the query is ready, it is time to build it. This step generates the actual Cypher® string that can be used in a Neo4j database:
const { cypher } = clause.build(); console.log(cypher);
Conclusion
Your full script should look like this:
import Cypher from "@neo4j/cypher-builder";
const movieNode = new Cypher.Node();
const matchPattern = new Cypher.Pattern(movieNode, { labels: ["Movie"] });
const clause = new Cypher.Match(matchPattern).return(movieNode);
const { cypher } = clause.build();
console.log(cypher);
If you execute node main.js again, it outputs the following query:
MATCH (this0:Movie)
RETURN this0
|
Note that |