[英]Cypher: Loop over distinct nodes in multiple paths
I have a neo4j graph with nodes that I need to increment a flag on all of the nodes on paths from a start to end node.我有一个带有节点的 neo4j 图,我需要在从开始节点到结束节点的路径上的所有节点上增加一个标志。 But I need to increment this flag only ONCE, even if it lies on multiple paths.但是我只需要增加这个标志一次,即使它位于多个路径上。
I use the following query, but obviously it loops through all of the paths so the flag is incremented more than once:我使用以下查询,但显然它循环遍历所有路径,因此标志不止一次递增:
MATCH paths = (end:Operation)-[DEPENDS_ON*]->(start:Operation )
WHERE id(start) = 304
AND end.final = true
UNWIND [ops IN nodes(paths)] AS op
SET op.flag = op.flag + 1
How can I unwind or collect the distinct nodes on all paths then increment the property?如何展开或收集所有路径上的不同节点然后增加属性?
What about this?那这个呢?
WITH COLLECT(DISTINCT ops) AS distinctOps
MATCH paths = (end:Operation)-[DEPENDS_ON*]->(start:Operation )
WHERE id(start) = 304
AND end.final = true
UNWIND nodes(paths) AS ops
WITH COLLECT(DISTINCT ops) AS distinctOps
FOREACH (op IN distinctOps |
SET op.flag = op.flag + 1
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.