查询

本页展示如何使用 Cypher 构建器创建以下简单的 Cypher® 查询,以 MATCHRETURN 电影

MATCH(m:Movie)
RETURN m

说明

  1. 通过创建 Cypher.Node 的新实例来定义节点变量

    const movieNode = new Cypher.Node();
  2. 使用 Cypher.Pattern 创建要匹配的模式

    const matchPattern = new Cypher.Pattern(movieNode, { labels: ["Movie"] });
  3. 创建一个 MATCH 子句,并将模式作为参数传入

    const clause = new Cypher.Match(matchPattern);
  4. RETURN 节点变量,请在 MATCH 子句中使用 .return 方法

    clause.return(movieNode);
    1. 或者,你也可以通过单行语句创建该子句来实现相同的功能

      const clause = new Cypher.Match(matchPattern).return(movieNode);
  5. 查询准备好后,就可以构建它。此步骤会生成可在 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

请注意,this0 是 Cypher 构建器为创建的节点变量自动生成的名称。

© . This site is unofficial and not affiliated with Neo4j, Inc.