apoc.refactor.collapseNode

Procedure

apoc.refactor.collapseNode(nodes ANY, relType STRING) - collapses the given NODE and replaces it with a RELATIONSHIP of the given type.

Signature

apoc.refactor.collapseNode(nodes :: ANY, type :: STRING) :: (input :: INTEGER, output :: RELATIONSHIP, error :: STRING)

Input parameters

Name Type Default Description

nodes

ANY

null

nodes can be of type STRING (elementId()), INTEGER (id()), NODE or LIST<STRING | INTEGER | NODE>.

type

STRING

""

The type of the RELATIONSHIP to create out of the given NODE values.

Output parameters

Name Type

input

INTEGER

output

RELATIONSHIP

error

STRING

Usage Examples

The examples in this section are based on the following sample graph:

CREATE (flight:Flight {number: "BA001"})
CREATE (origin:Airport {code: "LHR"})
CREATE (destination:Airport {code: "AMS"})
CREATE (flight)<-[:OUT]-(origin)
CREATE (flight)-[:IN]->(destination);

The following query collapses the Flight node, replacing it with a CONNECTED to relationship:

MATCH (flight:Flight {number: "BA001"})
CALL apoc.refactor.collapseNode([flight],'CONNECTED_TO')
YIELD input, output
RETURN input, output;
Table 1. Results
input output

10

[:CONNECTED_TO {number: "BA001"}]

If we execute this query, it will result in the following graph:

apoc.refactor.collapseNode