1

Consider that I'm working on a graph database and there are some nodes at some label i.e labe14 and now what I want to do is to update the properties of all the nodes and add the another one at once to each of them. How could it be done?

To add or update the property of a single node I know I can use this command:

    MATCH (n:label4 {id: 123})
SET n.newProperty = 'new value'

However how to do this for many nodes at once using a single Cypher Query?

Hoping for a great help!

7 Answers7

1

You can modify your MATCH clause as follows:

  MATCH (n:label4)
  SET n.newProperty = 'new value', n.newProperty2 = 'value'
  RETURN n

This will match all nodes with label4, update and then return them.

han
  • 74
  • 7
0

Your match clause currently updates the property of a single node.

MATCH (n:label4 {id: 123})
SET n.newProperty = 'new value'

Modifying above query will answer your question.

MATCH (n:label4)
SET n.Property = 'new value', n.Property2 = 'new value2'

Above query will Update the 'Property' property and add another value Property2 to all the nodes with 'label4' label. You can also change the values as needed.

Talha Munir
  • 121
  • 5
0

With the more recent version (1.3.0) you can update like as in a map.

As so:

MERGE (n:label1)
SET n = {
    prop1: 'Prop 1 value',
    prop2: 'Prop 2 value'
    }
RETURN n $$) as (v agtype);
RU-D
  • 224
  • 8
0

You can modify it to update properties of multiple nodes with a single cypher query Try using 'set' Clause along with the match clause that match all nodes with given label and then update the properties of each node using 'SET'

HERE IS example how you can do this:

MATCH ( n: mylabel)
SET n.newProperty= 'new Value' , n.anotherProperty = 'another value'
farrukh raja
  • 187
  • 4
0

Currently your match clause is updating the property of a single node. Modify it as below code:

MATCH (n:label4) SET n.newProperty = 'new value', n.newProperty2 = 'value' RETURN n

Aadil Bashir
  • 111
  • 5
0

To update multiple nodes is pretty much same as updating a single node, all you need to do is make sure you match all the nodes you need to update. Here for instance matching all label with label4

MATCH (n:label4)
SET n.newProperty = 'new value', n.moreproperty = ‘any value’…
Peter
  • 43
  • 4
-1

To add or update the property of all nodes with Label label4, we can use this query.

SELECT * FROM cypher('graph_name', $$
MATCH (n:label4)
SET n.newProperty = 'new value'
$$) as (v agtype);

Explanation:

MATCH (n:label4) will give all the nodes with Label label4. SET n.newProperty = 'new value' will set the newProperty of all those nodes (with label4) with value new value.