Neo4j添加/更新属性(如果存在节点) [英] Neo4j Add/update properties if node exists
问题描述
我希望能够通过上载该数据库的新版本或该数据库的一部分来update/enlarge
我的Neo4j数据库.
I want to be able to update/enlarge
my Neo4j database by uploading a newer version of that database OR part of that database.
我发现,我可以使用MERGE
来add
新节点,即使它们尚不存在.但是在此过程中,如何以精简的方式add
将新属性添加到该现有节点(如果不存在)?
Of what I've found I can use MERGE
to add
new nodes just if they don't already exists. But in that process, how do I in a slimmed way add
new properties to that existing node if they don't exist?
即,如果我有一个节点'John' of 'Age:34' and 'Hair:brown'
并上传'John'/'Age:34'/'Coat:Yellow'
-如何获取'John'/'Age:34'/'Hair:brown'/'Coat:Yellow'
.
I e, if I have a node 'John' of 'Age:34' and 'Hair:brown'
and upload 'John'/'Age:34'/'Coat:Yellow'
- how do I get 'John'/'Age:34'/'Hair:brown'/'Coat:Yellow'
.
推荐答案
您可以合并 John 上的节点(或主要标识属性).然后在成功合并后设置属性.
You could merge the node on John (or the primary identifying attribute). And then set the properties after the successful merge.
您可以一次为所有属性设置一个地图
You could set them all at once with a map for all attributes
MERGE (n:Node {name: 'John'})
SET n = {name: 'John', age: 34, coat: 'Yellow', hair: 'Brown'}
RETURN n
如果您只想替换属性 age 和外套,则可以这样做.
If you just wanted to replace the attributes age and coat, you could do this instead.
MERGE (n:Node {name: 'John'})
SET n.age = 34, n.coat = 'Yellow'
RETURN n
或者您也可以将其添加为地图
Or you could add it as a map too
MERGE (n:Node {name: 'John'})
SET n += {age: 34, coat: 'Yellow'}
RETURN n
这篇关于Neo4j添加/更新属性(如果存在节点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!