【发布时间】:2020-01-16 16:22:20
【问题描述】:
我正在尝试返回两组节点,然后将它们作为一组返回。
我有一个 WHERE ALL 子句会中断查询,但我不知道为什么。
我还想知道如何连接两个节点集合,因此将 childItems 附加到 parentItems 的单个级别列表中。我不相信我用“+”正确地做到了。
MATCH (ic: itemCollection)-[:CONTAINS]->(ii: itemInstance)
WITH COLLECT(ii) AS parentItem, ic, ii
OPTIONAL MATCH p = (ii)-[*]->(:item)-[:INSTANCE]->(childItem: ItemInstance)
// get asset children
SET ic.lastAccess = timestamp()
WITH parentItem, [n IN nodes(p) WHERE 'itemInstance'
IN labels(n) AND NOT(n.id = ii.id) | n] AS childItems, p, ic
// RETURN parentItem, childItems - will return the parentItem node, and the childItem nodes here, but not after the WHERE ALL clause
WHERE ALL(n IN childItems WHERE (ic)-[:CONTAINS]-(n))
//merge parent with children
WITH parentItem , childItems, p
WITH parentItem + childItems AS itemList, p
UNWIND itemList AS item
RETURN item
任何帮助将不胜感激。
【问题讨论】:
-
顺便说一下,您的查询还有其他问题。例如,
parentItem将始终只包含一个节点,因为ii被用作聚合分组键之一。另外,你真的需要MATCH成为OPTIONAL吗?
标签: neo4j