问题
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