Neo4J Update Command Day 3

 

Neo4J Commands Lab Day 3



Update and Set Commands:

  • The SET clause is used to update labels on nodes
  •  The SET clause is used to update properties on nodes and relationships.





Set a Property :

Use SET to set a property on a node or relationship:



  • MATCH (n {name: 'Andy'})
  • SET n.surname = 'Taylor'
  • RETURN n.name, n.surname


Update a Property

SET can be used to update a property on a node or relationship. This query forces a change of type in the age property:


  • MATCH (n {name: 'Andy'})
  • SET n.age = 26
  • RETURN n.name, n.age



  • MATCH (n {name: 'Andy'})
  • SET n.age = toString(n.age)
  • RETURN n.name, n.age



Remove a Property

Although REMOVE is normally used to remove a property, it is sometimes convenient to do it using the SET command. A case in point is if the property is provided by a parameter.



  • MATCH (n {name: 'Andy'})
  • SET n.name = null
  • RETURN n.name, n.age



Remove All Properties Using an Empty Map and =

All existing properties can be removed from a node or relationship by using 

SET with = and an empty map as the right operand:

  • CREATE (p:Person {name: 'Peter'})
  • MATCH (p {name: 'Peter'})
  • SET p = {}
  • RETURN p.name, p.age




Set Multiple Properties Using one SET Clause:

Set multiple properties at once by separating them with a comma:


  • MATCH (n {name: 'Tom'})
  • SET n.position = 'Developer', n.surname = 'Taylor'



Set a Label on a Node:

Use SET to set a label on a node:



  • CREATE (p:Person {name: 'Michael'})
  • WITH p
  • MATCH (n {name: 'Michael'})
  • SET n:German
  • RETURN n.name, labels(n) AS labels



Set Multiple Labels on a Node:

Set multiple labels on a node with SET and use : to separate the different labels:





  • CREATE (p:Person {name: 'Kelly'})
  • WITH p
  • MATCH (n {name: 'Kelly'})
  • SET n:Swedish:Bossman
  • RETURN n.name, labels(n) AS labels



No comments:
Write comments

Please do not enter spam links

Meet US

Services

More Services