0

I have a vertex named CAR which has a few attributes as follows:

CREATE (v:Car{
    name: 'Alex',
    age: 27,
    manufactureDate: 2023
    color: Yellow
})

Now I want to delete the color property from the node. Can someone help me with this

cybersam
  • 63,203
  • 6
  • 53
  • 76

3 Answers3

1

You can use the REMOVE clause as follows:

SELECT * FROM cypher('graph_name', $$
MATCH (u: Car {name : 'Alex'})
REMOVE u.color
RETURN u
$$) AS (u agtype);

Read more here in the documentation

Moreover, another way is to simply set the property to NULL (A property can not have a NULL value so the property is dropped)

SELECT * FROM cypher('graph_name', $$
MATCH (u: Car {name : 'Alex'})
SET u.color = NULL
RETURN u
$$) AS (u agtype);
Zainab Saad
  • 728
  • 1
  • 2
  • 8
0

You can delete the node property using other properties of the node like in that case you can delete it with using name, age or manufacture date.

You have to keep one thing in mind that it will remove that property from every nodes that have the given condition like if age:27 for multiple nodes then for all nodes that have age as 27 the color property will be removed.

So, use that property in condition that is unique or what we say is primary key so that the data which you don't want to change remains same.

Using age property

Select * FROM cypher('graph',$$ 
MATCH(u: Car {age: 27})
REMOVE u.color
RETURN u
$$) AS (u agtype);

Using name property

Select * FROM cypher('graph',$$ 
MATCH(u: Car {name: 'Alex'})
REMOVE u.color
RETURN u
$$) AS (u agtype);

Using manufacturedate property

Select * FROM cypher('graph',$$ 
MATCH(u: Car {manufactureDate: 2023})
REMOVE u.color
RETURN u
$$) AS (u agtype);
0

To delete the color property from the node Car, you need to use MATCH clause to find the node with specified properties and the REMOVE clause to remove the specific property. The query would look like below

MATCH (v:Car{name:'Alex', age: 27, manufactureDate: 2023})
REMOVE v.color
ShaHeen
  • 59
  • 5