cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to perform an active action in the ALL predicate?

I need to assign a value to a variable in the all predicate, how do I do this? I want approximately the following

MATCH p=(start:PORTS {N_ID: "180992417"})-[r*1..10]-(end:PORTS {N_ID: "12645867"})
with p, null as AGG
WHERE ALL(rel In r WHERE type(rel) IN ["r","port"] set AGG = rel.AGG)
RETURN * LIMIT 1

You need to run set AGG = rel.AGG at each step of the cycle.
How do I do this?

7 REPLIES 7

shan
Graph Buddy

I am trying to understand your question.
is it possible for a path p to contain relationships of both type r and port? If so, what is the expected behaviour? Maybe it'd be easier to understand if you explain your query in English.

By the way, conventionally, node labels should be camel case (e.g., Ports) and relationships type should be all uppercase (e.g., PORT).

all() is a list predicate, it can only be used to evaluate a boolean based upon if all elements in the list adhere to the contained predicate. As such it cannot be used as any kind of updating structure.

I think what you want to do is use a FOREACH over a filtered list.

That said, I don't understand what you're trying to do with AGG. You haven't shown how you mean to use this, or what cycle you're referring to.

I need to collect values from [:r] at each iteration of the loop into a some variable

That is a means. But we don't know to what end. Please give a more comprehensive example showing the problem and desired output. There may be other approaches that could be used to fulfill what you want to do.

And whether a FOREACH is the right approach or not depends upon getting the full picture.

Drew schematically. The relationships have a parameter and we go from the start node. Look at the parameter of the start node. In the example, it is 2. This means that the path must be selected further using this initial parameter, i.e. = 2. The rest of the path is not valid. How do I make it not try to go over links that have a parameter that is not equal to the initial parameter (that is, 2)2X_0_0aa72dbdc832f05b2cae4da6c2d1613e2b3102b6.png

We are discussing a similar topic in another topic. Please look in another topic

"I think what you want to do is use a FOREACH over a filtered list."

Yes, perhaps so. How do I do this?