查询
本页展示如何使用 Cypher 构建器创建以下简单的 Cypher® 查询,以 MATCH 并 RETURN 电影
MATCH(m:Movie)
RETURN m
说明
-
通过创建
Cypher.Node的新实例来定义节点变量const movieNode = new Cypher.Node(); -
使用
Cypher.Pattern创建要匹配的模式const matchPattern = new Cypher.Pattern(movieNode, { labels: ["Movie"] }); -
创建一个
MATCH子句,并将模式作为参数传入const clause = new Cypher.Match(matchPattern); -
要
RETURN节点变量,请在MATCH子句中使用.return方法clause.return(movieNode);-
或者,你也可以通过单行语句创建该子句来实现相同的功能
const clause = new Cypher.Match(matchPattern).return(movieNode);
-
-
查询准备好后,就可以构建它。此步骤会生成可在 Neo4j 数据库中使用的实际 Cypher 字符串
const { cypher } = clause.build(); console.log(cypher);
结论
你的完整脚本应如下所示
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);
如果再次执行 node main.js,它会输出以下查询
MATCH (this0:Movie)
RETURN this0
|
请注意, |