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
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
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);
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.
Select * FROM cypher('graph',$$ MATCH(u: Car {age: 27}) REMOVE u.color RETURN u $$) AS (u agtype);
Select * FROM cypher('graph',$$ MATCH(u: Car {name: 'Alex'}) REMOVE u.color RETURN u $$) AS (u agtype);
Select * FROM cypher('graph',$$ MATCH(u: Car {manufactureDate: 2023}) REMOVE u.color RETURN u $$) AS (u agtype);
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