简体   繁体   English

Neo4j Cypher查询中的MERGE子句不起作用

[英]MERGE clause in Neo4j Cypher query not working

I am running neo4j-community-3.0.0-M05. 我正在运行neo4j-community-3.0.0-M05。

I am trying out Neo4J Cypher Query Language's MERGE clause. 我正在尝试Neo4J Cypher查询语言的MERGE子句。 Its explanation is given as follows 它的解释给出如下

It acts like a combination of MATCH or CREATE , which checks for the existence of data first before creating it. 它的作用类似于MATCHCREATE的组合,后者在创建数据之前先检查数据是否存在。 With MERGE you define a pattern to be found or created. 使用MERGE您可以定义要查找或创建的模式。 Usually, as with MATCH you only want to include the key property to look for in your core pattern. 通常,与MATCH一样,您只希望在核心模式中包括要查找的key属性。 MERGE allows you to provide additional properties you want to set ON CREATE . MERGE允许您提供要设置为ON CREATE其他属性。

I already have following node: 我已经有以下节点:

(:Movie{title:"Forrest Gump", released:1994})

and now I wanted to add a dummy property addedOn with dummy value 20160108 to it just to try out MERGE clause: 现在我想向其中添加一个哑元属性addedOn和哑元值20160108 ,以尝试MERGE子句:

MERGE (a:Movie{title:"Forrest Gump"}) 
ON CREATE SET a.addedOn= "20160108" 
RETURN a;

However this seems not working: 但是,这似乎不起作用:

在此处输入图片说明

Why is this so? 为什么会这样呢?

What you're seeing is precisely the expected behaviour. 您所看到的正是预期的行为。

Since MERGE finds your pre-existing Forrest Gump, this node is used. 由于MERGE找到了您预先存在的阿甘正传,因此使用了该节点。 The ON CREATE handler will not fire since you didn't create anything. 由于您未创建任何内容,因此ON CREATE处理程序将不会触发。

If you've had a ON MATCH handler this one would have been fired since MERGE 's match was successful. 如果您拥有ON MATCH处理程序,则由于MERGE的匹配成功,因此将触发该处理程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM