Mahesha999
Mahesha999

Reputation: 24721

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:

enter image description here

Why is this so?

Upvotes: 0

Views: 399

Answers (1)

Stefan Armbruster
Stefan Armbruster

Reputation: 39905

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.

Upvotes: 2

Related Questions