Search code examples
neo4jcypher

Neo4j Cypher update node dynamic properties


I have the following Neo4j nodes: Value. Each Value node can have 0..N properties in the following format:

Value1 node properties:
    property.1 = 123
    property.23 = 1
    property.452 = 5

Value2 node properties:
    property.45 = 90
    property.4 = 7

...

ValueN node properties:
    property.12 = 2
    property.46 = 17
    property.101 = 32
    property.3000 = 84

I don't know the certain number of these properties for every Value node but during the Cypher query, I need to update all of them.

I need to write Cypher query that will update all Value nodes in the database and increment every value of every Value.property.X +1.

Please note that the Value node can also contains other properties but I only need to update the properties in the mentioned format: property.X where X can be any number.

Please show how it can be done.


Solution

  • Try something like

    MATCH (n:Node)
    UNWIND keys(n) as key
    WITH n,key where key contains 'property.'
    SET n['key'] = n['key'] + 1