How to push values to property array Cypher-Neo4j

SarathSprakash picture SarathSprakash · Feb 24, 2014 · Viewed 13.4k times · Source

I am new to Neo4j,I have two nodes user and files with a relationship :contains, the relationship has a property idwhich is an array, represented as

(:user)-[:contains{id:[12345]}]->(:files)

However I want to populate the property array id with values 1111 and 14567 sequentially using Cypher queries, I dont find any method to push values into the array.

after inserting 1111 to property id it will be

(:user)-[:contains{id:[12345,1111]}]->(:files)

after inserting 14567 to property id it will be

(:user)-[:contains{id:[12345,1111,14567]}]->(:files)

I dont know how to populate values to an property array sequentially

Please help, Thanks in advance

Answer

jjaderberg picture jjaderberg · Feb 24, 2014

Adding values to an array is analogous to incrementing an integer or concatenating a string and is signified the same way, in your case (let c be your [c:contains {id:[12345]}])

c.id = c.id + 1111             //  [12345,1111]
c.id = c.id + 14567            //  [12345,1111,14567]

or

c.id = c.id + [1111,14567]     //  [12345,1111,14567]