apoc.create.setProperties

Details

Syntax

apoc.create.setProperties(nodes, keys, values) :: (node)

Description

Sets the given properties to the given NODE values.

Input arguments

Name

Type

Description

nodes

ANY

The nodes to set properties on.

keys

LIST<STRING>

The property keys to set on the given nodes.

values

LIST<ANY>

The values to assign to the properties on the given nodes.

Return arguments

Name

Type

Description

node

NODE

The updated node.

Set Properties using Cypher

Properties can be referenced dynamically in Cypher without using APOC.

Cypher syntax for dynamically setting a property on a node or a relationship
SET n[key]

The dynamically calculated key must evaluate to a STRING value. For more information, see the Cypher Manual → Dynamically setting or updating a property.

Usage Examples

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

CREATE (jennifer:Person {name: "Jennifer", community: 1, partition: 4})
CREATE (karin:Person {name: "Karin", community: 4, partition: 2})
CREATE (elaine:Person {name: "Elaine", community: 3, partition: 3})
MERGE (jennifer)-[:FRIENDS {since: datetime("2019-06-01")}]-(karin)
MERGE (jennifer)-[:FRIENDS {since: datetime("2019-05-04")}]-(elaine);

We can duplicate all properties on Person nodes using both APOC and Cypher:

apoc.create.setProperties
MATCH (p:Person)
WITH p, keys(p) AS keys
CALL apoc.create.setProperties(p,[k in keys | k + "Copy"], [k in keys | p[k]])
YIELD node
RETURN node
Using Cypher’s dynamic properties
MATCH (p:Person)
FOREACH (k IN keys(p) | SET p[k + "Copy"] = p[k])
RETURN p AS node
Results
node

{"name":"Jennifer","partition":4,"community":1,"nameCopy":"Jennifer","partitionCopy":4,"communityCopy":1}

{"name":"Karin","partition":2,"community":4,"nameCopy":"Karin","partitionCopy":2,"communityCopy":4}

{"name":"Mark","partition":3,"community":3,"nameCopy":"Mark","partitionCopy":3,"communityCopy":3}