Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-27-2021 11:42 AM
Hello,
I have a graph and I'm working with connections between nodes A and B with a broker node X as follows:
(A)-[]-(X)-[]-(B)
Now I need to add a new edge between A and B in a case that there are at least 3 distinct broker nodes X, e.g.:
(A)-[]-(X1)-[]-(B)
(A)-[]-(X2)-[]-(B)
(A)-[]-(X3)-[]-(B)
I'm failing at the match part while I do not know how to properly count the broker nodes X and how to add it into the where
part of the query, my try:
match p=(A)-[]-(X)-[]-(B)
where
count(X) > 3
return p
but this does not work and I understand that it won't work like this. Can you help me please?
Thank you very much in advance.
Solved! Go to Solution.
10-27-2021 02:22 PM
@ldpubsec
If you don't need the return value of p, how about this?
MATCH (a:A)-[]-(X)-[]-(b:B)
WITH a,b,count(X) AS countx
WHERE countx > 3
RETURN a,b
10-27-2021 01:33 PM
Hi @ldpubsec
CREATE (a:A)-[:CONNECTION]->(:X)-[:CONNECTION]->(b:B),
(a)-[:CONNECTION]->(:X1)-[:CONNECTION]->(b),
(a)-[:CONNECTION]->(:X2)-[:CONNECTION]->(b),
(a)-[:CONNECTION]->(:X3)-[:CONNECTION]->(b)
The code is not cool but work.
MATCH (a:A)-[]-(X)-[]-(b:B)
WITH a,b,count(X) AS countx
MATCH p=(a)-[]-()-[]-(b)
WHERE countx > 3
RETURN p
10-27-2021 01:55 PM
Thank you! This works!
May I ask how does it work? I'm a little puzzled by the double match
, the first is ok with the following with
, but why is there the second match
? Thank you in advance.
10-27-2021 02:22 PM
@ldpubsec
If you don't need the return value of p, how about this?
MATCH (a:A)-[]-(X)-[]-(b:B)
WITH a,b,count(X) AS countx
WHERE countx > 3
RETURN a,b
All the sessions of the conference are now available online