我正在尝试创建一个实体,该实体的属性包含一个数组/项列表。我不知道该怎么办:
任何线索将不胜感激。
这有助于解决我面临的多对一关系问题。
答案 0 :(得分:1)
// 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" |
+------+