apoc.nodes.link

Procedure APOC Core

apoc.nodes.link([nodes],'REL_TYPE', conf) - creates a linked list of nodes from first to last

Signature

apoc.nodes.link(nodes :: LIST? OF NODE?, type :: STRING?, config = {} :: MAP?) :: VOID

Input parameters

Name Type Default

nodes

LIST? OF NODE?

null

type

STRING?

null

config

MAP?

{}

Config parameters

This procedure supports the following config parameters:

Table 1. Config parameters
name type default description

avoidDuplicates

boolean

false

If true, the relationship will not be created, if it already exists

== Usage Examples The examples in this section are based on the following sample graph: [source,cypher] ---- CREATE (:Event {name: "Event 1", date: datetime("2019-06-01")}) CREATE (:Event {name: "Event 2", date: datetime("2019-06-04")}) CREATE (:Event {name: "Event 3", date: datetime("2019-06-08")}); ----

We can create a linked list of these events, by running the following query:

[source,cypher] ---- MATCH (e:Event) WITH e ORDER BY e.date WITH collect(e) AS events CALL apoc.nodes.link(events, "NEXT") RETURN count(*); ----

image::linked-list-events.svg[scaledwidth="100%"]

We can check for relationship existence using the {avoidDuplicates: true} configuration; calling the previous query twice, 2 relations of type "NEXT" will be created between the nodes, instead, by executing CALL apoc.nodes.link(events, "NEXT", {avoidDuplicates: true}) only one relationship of type "NEXT" will be created.

More documentation of apoc.nodes.link