apoc.create.nodes

Details

Syntax

apoc.create.nodes(labels, props) :: (node)

Description

Creates NODE values with the given dynamic labels.

Input arguments

Name

Type

Description

labels

LIST<STRING>

The labels to assign to the new nodes.

props

LIST<MAP>

The properties to assign to the new nodes.

Return arguments

Name

Type

Description

node

NODE

The created node.

Creating nodes with dynamic labels using Cypher

Labels can be referenced dynamically in Cypher without using APOC.

Cypher syntax for creating a label dynamically
CREATE (n:$(label))

The dynamically calculated label must evaluate to a STRING or LIST<STRING>. For more information, see the Cypher Manual → CREATE nodes and relationships using dynamic node labels and relationship types.

Usage Examples

The example below demonstrates how to use Cypher and APOC to create nodes by passing in their labels and properties dynamically using a map:

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"}]);
apoc.create.node
CALL apoc.create.nodes($labels, $properties);
CREATE clause
UNWIND $properties AS propertyMap
CREATE (node:$($labels) propertyMap)
RETURN node;
Results
node

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

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