【问题标题】:Neo4J - WHERE ALL clause is breaking the match on nodesNeo4J - WHERE ALL 子句正在破坏节点上的匹配
【发布时间】: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


【解决方案1】:

如果p 为空,则WHERE ALL 中断。为了解决这个问题,我使用 coalesce(childAssets, []) 将 null 转换为空列表。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-30
    • 1970-01-01
    相关资源
    最近更新 更多