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

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

问题描述

我希望能够通过上传该数据库的更新版本或该数据库的一部分来更新/放大我的 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' 的 'Age:34' 和 '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

如果您只想替换属性 agecoat,您可以改为这样做.

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天全站免登陆