arrays - 如何在 NEO4 Cypher 中创建属性数组?
问题描述
我正在尝试创建一个具有包含项目数组/列表的属性的实体。我不明白我该怎么做:
- 创建属性数组
- 对数组执行追加
- 解析数组属性
任何线索将不胜感激。
这有助于解决我面临的多对一关系问题。
解决方案
// 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" |
+------+
推荐阅读
- reactjs - tsconfig baseURL 和路径使构建导入指向源文件夹
- java - 在给定的数字数组中找到最大的序列
- python - 如何从python中的dask中读取表
- ios - 使用 AutoLayout 在 UIView 中定位百分比定位的子视图
- r - 如何用R中的字符串字符替换一系列int值
- javascript - 如何计算 Angular 2+(SPA)中的页面加载时间?
- apache-kafka - kafka集群中的多个消费者
- python - 尽管有属性,如何在 Python XML 中的同一父级中加入具有相同标签的元素?
- regex - 在 oracle 中从 json 中提取值
- python-3.x - 如何检测 PySpark 正在本地机器上运行