首页 > 解决方案 > (Neo4j) 在后续查询中携带变量

问题描述

我试图通过 2 个后续查询来传递一个变量。似乎 WITH 仅有助于将变量传递到下一个查询,但在此之前没有任何作用。建议?

这是我正在尝试做的示例:
Person 节点包含有关出版商、作家和编辑的信息(例如姓名、性别等)
Story 节点包含有关 Story 的数据(例如标题、发布日期等)
IN 关系具有类别: 创建、编辑、发布

返回编辑了其他编辑出版商发布的故事的编辑出版商:
假设没有重复的人名

  1. 查找所有编辑过至少一篇文章并发表过至少一篇文章的人
  2. 查找这些编辑出版商发表的故事列表 1
  3. 在 2 中故事的所有编辑器中,返回这些编辑器的子列表也在 1 中
MATCH (EditorPublisher:Person)-[:IN{category: "published"}]->(:Story)   // 1
WHERE (EditorPublisher:Person)-[:IN{category: "edited"}]->(:Story)
WITH COLLECT(EditorPublisher.name) as EditorPublisher_list
 
MATCH (EditorPublisher_stories:Story)<-[:IN{category: "published"}]-(publisher:Person) // 2
WHERE publisher.name in EditorPublisher_list
WITH EditorPublisher_list            // throws error EditorPublisher_list variable not found
WITH COLLECT(EditorPublisher_stories.title) as EditorPublisher_stories_list
  
MATCH (epe:Person)-[contribution:PLAYED]-(eps:Movie) // 3
WHERE epe.name in EditorPublisher_list
    AND eps IN EditorPublisher_stories_list
RETURN epe.name

标签: variablesneo4jpipewith-statement

解决方案


NVM 我让它工作。如果我不重命名变量,With 会保留变量。

我只需要做 WITH return.nodes,并在后续查询中调用 return.nodes 而不是在 [return.nodes.list] 中使用


推荐阅读