1

How to remove an element from an array in redisgraph

Consider the below data in the redisgraph database.

graph.query Test "MATCH (u:Person) Create (:Person {address:['something1', 'something2']})"

I need to remove something1 from the address list.

How can we achieve by writing a cypher query in redisgraph database?

Guy Korland
  • 9,139
  • 14
  • 59
  • 106
Bhanu
  • 25
  • 9

1 Answers1

1

Consider the following query, it will remove element at position 4 (0 base indexing)

127.0.0.1:6379> GRAPH.QUERY g "WITH [1,2,3,4,5,6,7,8,9,10] AS arr RETURN arr[..4] + arr[5..]"
1) 1) arr[..4] + arr[5..]
2) 1) 1) "[1, 2, 3, 4, 6, 7, 8, 9, 10]"
SWilly22
  • 869
  • 4
  • 5
  • Thanks for the suggestion @SWilly22 Is there any way to remove an element directly from array apart from INDEXED based removal of an attribute? some thing like below `graph.query Test "MATCH (n:Person) WHERE EXISTS (n.address) REMOVE "something1" IN n.address` – Bhanu Jan 09 '22 at 15:51
  • Consider the following query: WITH ['a', 'b', 'c'] AS arr UNWIND range(0, size(arr)) AS idx WITH arr, idx WHERE arr[idx] = 'b' RETURN arr[0..idx] + arr[idx+1..] – SWilly22 Jan 10 '22 at 20:18
  • Thank you very much @SWilly22 this helps. – Bhanu Jan 19 '22 at 16:45