I want to delete an element from an array property on a node using Cypher.
I know the value of the element I want to delete, but not its index.
e.g. suppose I have a node like
({some_array: ["apples", "oranges"]})
I want a query like (pseudocode):
MATCH (n)
REMOVE "oranges" IN n.some_array
The FILTER function is deprecated:
https://neo4j.com/docs/cypher-manual/current/functions/list/#functions-filter
They consider using [variable IN list WHERE predicate] instead. You just have to erase the filter() by brackets:
MATCH (n)
WHERE EXISTS(n.some_array)
SET n.array = [x IN n.some_array WHERE x <> "oranges"];
Worked in my case perfectly
Update:
Thanks ANONYMUS for pointing out that "HAS()" is replaced with "EXISTS()"
Cypher doesn't have functions for mutating arrays, but you can create a new array with "oranges"
removed using FILTER
:
MATCH (n)
WHERE HAS(n.some_array)
SET n.array = FILTER(x IN n.some_array WHERE x <> "oranges");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With