Add properties to Neo4j Dynamically

ε祈祈猫儿з 提交于 2020-01-04 04:04:08

问题


How to add a new property dynamically to an existing node ? Here I wan to assign both key and value dynamically to my chypher query.. Any suggestions will be highly appreciated :)


回答1:


You can create a map with key value pairs and add the pairs with SET.

Example 1: Add properties, will erase the others

WITH {name:"Kenny", age:10} as kv
MATCH (n:Person {uid:"123-fff"}) SET n = kv

Example 2: Append properties, will replace values of existing keys :

WITH {name:"Kenny", age:10} as kv
MATCH (n:Person {uid:"123-fff"}) SET n += kv

Ideally you would pass the kv's as query parameters, so the json sent for the query would be something like this :

{
  "statements": [
    {
      "statement": "MATCH (n:Person) SET n += {kv}",
      "params": {
        "kv": {
          "name": "kenny",
          "age": 10
        }
      }
    }
  ]
}


来源:https://stackoverflow.com/questions/32290523/add-properties-to-neo4j-dynamically

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