如何在 NEO4 Cypher 中创建属性数组?

Kel*_*n U 1 arrays neo4j cypher

我正在尝试创建一个具有包含项目数组/列表的属性的实体。我不明白我该怎么做:

  1. 创建属性数组
  2. 执行追加到数组
  3. 解析数组属性

任何线索将不胜感激。

这有助于解决我面临的多对一关系问题。

log*_*ima 5

// Create a node with an array prop
CREATE (n:Test { my_array:['a', 'b', 'c']}) RETURN n;
+-------------------------------------+
| n                                   |
+-------------------------------------+
| (:Test {my_array: ["a", "b", "c"]}) |
+-------------------------------------+

// append the value 'd' in the array
MATCH (n:Test) SET n.my_array=n.my_array+ 'd' RETURN n;
+------------------------------------------+
| n                                        |
+------------------------------------------+
| (:Test {my_array: ["a", "b", "c", "d"]}) |
+------------------------------------------+


// Remove the value 'b' from the array
MATCH (n:Test) SET n.my_array=filter(x IN n.my_array WHERE x <> 'b')  RETURN n;
+-------------------------------------+
| n                                   |
+-------------------------------------+
| (:Test {my_array: ["a", "c", "d"]}) |
+-------------------------------------+


// Don't forget the magic UNWIND  with arrays
MATCH (n:Test) UNWIND n.my_array AS item  RETURN item;
+------+
| item |
+------+
| "a"  |
| "c"  |
| "d"  |
+------+
Run Code Online (Sandbox Code Playgroud)