ldpubsec
(Ldpubsec)
October 27, 2021, 6:42pm
1
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.
koji
(Koji Annoura)
October 27, 2021, 8:33pm
2
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
1 Like
ldpubsec
(Ldpubsec)
October 27, 2021, 8:55pm
3
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.
koji
(Koji Annoura)
October 27, 2021, 9:22pm
4
@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
3 Likes