How to push values to property array Cypher-Neo4j

眉间皱痕 提交于 2019-11-30 11:57:58

问题


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


回答1:


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]



回答2:


In addition to the answer of jjaderberg in case that one of the attribute is null

SET n.id = coalesce(n.id, []) + n.additionalId

The coalesce goes through the comma seperated list inside the brackets from left to right and skips the Null values. So in this case if n.id is initially Null the coalesce would take the second parameter which is the empty array.



来源:https://stackoverflow.com/questions/21979782/how-to-push-values-to-property-array-cypher-neo4j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!