Showing results for 
Search instead for 
Did you mean: 

updating while im creating node


im trying to create node with label words in my database that already exist and wanna add new property(i use constraint method to have unique words name)

my query is :

merge (n:words{name:"'" , instance:"apostrophe"}) with (n) match (a:PartOfSpeech{abbr:'sym'}) merge (n)-[:IS{type:'pos'}]->(a)

 so i get an error i could fix it with 

merge (n:words{name:'‘'})
on match set n.instance = "apostrophe"
with (n) match (a:PartOfSpeech{abbr:'sym'}) merge (n)-[:IS{type:'pos'}]->(a)

but cause im sending query from js i wan to this be automatic is there any way


You should probably rethink your model a bit, it might be too generic. You can pull the instance:apostrophe into a node-label, also 'abbr:sym' and type:pos into a relationship-type, instead of using the generic :IS 

But yes if you want to update and you don't know if it exists a MERGE with an ON MATCH SET makes sense if you always want to set the instance then you can just use SET