yasithlokuge
yasithlokuge

Reputation: 263

How can I delete all the properties of a particular node using a cypher query on Neo4J

I need to get the exisiting properties of a node and delete all the node properties excluding id.

Upvotes: 1

Views: 176

Answers (2)

InverseFalcon
InverseFalcon

Reputation: 30397

The easiest way is actually to set a map on the node (this replaces the properties of the node with the properties in the map, and ensuring the map only contains the projected properties you want to keep:

MATCH (n:person)
WITH n, n {.id, ._int_version} as propsToKeep
SET n = propsToKeep

Upvotes: 2

yasithlokuge
yasithlokuge

Reputation: 263

Found the answer on https://markhneedham.com/blog/2019/03/14/neo4j-delete-dynamic-properties/

MATCH (n:person)
WITH n, [k in keys(n) where not k in ["id","_int_version"]] as keys
CALL apoc.create.removeProperties(n, keys) YIELD node
RETURN node;

Upvotes: 2

Related Questions