O'Reilly logo

Learning Neo4j 3.x - Second Edition by Rik Van Bruggen, Jérôme Baton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Update data

The logic is that to update one or more nodes, you need to MATCH them. Then, you set the new values of the properties that you want to update. Let's say that a year has passed. We need to update the ages of the Person nodes:

MATCH (n:Person{name:"Juliet"})WHERE n.age = 13SET n.age=14RETURN n ;

In a yearly batch, we can use the following query to update all the Person nodes:

MATCH (n:Person)SET n.age=n.age+1RETURN n ;

You will notice how fast it is on our little dataset. It did not take ages.

Note that it is possible to add labels dynamically, and also to remove them.

Add the Teen label to that Person nodes with an age greater than 12 and lower than 18:

MATCH (n:Person)WHERE n.age>=12 AND n.age <18SET n:TeenRETURN n ;

You can remove ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required