apoc.create.nodes

Procedure APOC Core

apoc.create.nodes(['Label'], [{key:value,…​}]) create multiple nodes with dynamic labels

Signature

apoc.create.nodes(label :: LIST? OF STRING?, props :: LIST? OF MAP?) :: (node :: NODE?)

Input parameters

Name Type Default

label

LIST? OF STRING?

null

props

LIST? OF MAP?

null

Output parameters

Name Type

node

NODE?

Usage Examples

This procedure provides a more flexible way of creating nodes than Cypher’s CREATE clause.

The example below shows equivalent ways of creating a node with the Person and Actor labels, with a name property of "Tom Hanks":

apoc.create.node
CALL apoc.create.nodes(["Person", "Actor"], [{name: "Tom Hanks"}]);
CREATE clause
CREATE (node:Person:Actor {name: "Tom Hanks"})
RETURN node;
Table 1. Results
node

(:Person:Actor {name: "Tom Hanks"})

But this procedure is mostly useful for creating nodes that have dynamic labels or properties. For example, we might want to create a node with labels or properties passed in as parameters.

The following creates labels and properties parameters:

:param labels =>  (["Human", "MovieStar"]);
:param properties => ([{name: "Tom Cruise", placeOfBirth: "Syracuse, New York, United States"}, {name: "Reese Witherspoon", placeOfBirth: "New Orleans, Louisiana, United States"}]);

The following creates nodes with labels and properties based on the previously defined parameters:

CALL apoc.create.nodes($labels, $properties);
Table 2. Results
node

(:Human:MovieStar {name: "Tom Cruise", placeOfBirth: "Syracuse, New York, United States"})

(:Human:MovieStar {name: "Reese Witherspoon", placeOfBirth: "New Orleans, Louisiana, United States"})