Return

This page describes how to create a RETURN clause with the Cypher®.Return class.

You can add return clauses with new Cypher®.Return. However, more commonly they are added after an existing clause, such as MATCH, by using the method .return. In both cases, the return variables can be passed as parameters:

const node = new Cypher.Node();
const returnQuery = new Cypher.Return(node, new Cypher.Literal(10));

This generates the following RETURN clause:

RETURN this0, 10

Any expression can be passed to return, for example a function:

const returnQuery = new Cypher.Return(Cypher.round(new Cypher.Param(2.3)));

This translates to:

RETURN round($param1)

Aliasing results

You can alias results by using an array with two elements - the variable and the aliased name, which can be a string or a variable:

const node = new Cypher.Node();
const returnQuery = new Cypher.Return([node, "my-node"]);

This generates the following clause:

RETURN this0 AS my-node

Unique results

Add DISTINCT to RETURN by using the .distinct method:

const returnQuery = new Cypher.Return(node).distinct();

This generates the following clause:

RETURN DISTINCT this0