动态地向Neo4j添加属性 [英] Add properties to Neo4j Dynamically
本文介绍了动态地向Neo4j添加属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何动态地向现有节点添加新属性?在这里,我希望为我的密码查询动态分配键和值..任何建议将不胜感激:)
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 :)
推荐答案
您可以创建包含键值对的地图,并使用SET
添加这些对.
You can create a map with key value pairs and add the pairs with SET
.
示例1:添加属性,将删除其他属性
Example 1: Add properties, will erase the others
WITH {name:"Kenny", age:10} as kv
MATCH (n:Person {uid:"123-fff"}) SET n = kv
示例2:追加属性,将替换现有键的值:
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
理想情况下,您会将kv作为查询参数传递,因此为查询发送的json如下所示:
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
}
}
}
]
}
这篇关于动态地向Neo4j添加属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文