简体   繁体   中英

MERGE clause in Neo4j Cypher query not working

I am running neo4j-community-3.0.0-M05.

I am trying out Neo4J Cypher Query Language's MERGE clause. 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. With MERGE you define a pattern to be found or created. Usually, as with MATCH you only want to include the key property to look for in your core pattern. MERGE allows you to provide additional properties you want to set 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:

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. The ON CREATE handler will not fire since you didn't create anything.

If you've had a ON MATCH handler this one would have been fired since MERGE 's match was successful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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