Neo4j添加/更新属性(如果存在节点) [英] Neo4j Add/update properties if node exists

查看:4394
本文介绍了Neo4j添加/更新属性(如果存在节点)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够通过上载该数据库的新版本或该数据库的一部分来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.

我发现,我可以使用MERGEadd新节点,即使它们尚不存在.但是在此过程中,如何以精简的方式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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆