Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-15-2021 03:53 PM
have a graph that contains nodes and relationships like what I draw in the picture, I want a collection of all cS nodes, but my CQL only returns one per line in text view, how can I get the result I need? ( I need something like [firstCS, secondCS, thirdCS])
MATCH (rD:d)-[:IHF]->(rK)-[:HC]->(cS:c)
WITH rD, cS
WITH rD, cS, SIZE( ()-[:HC]->(cS) ) AS Csum
RETURN rD.name, cS.name, Csum
02-15-2021 04:08 PM
couple of issues.
your cypher describes a relation of [:HS]
but yet your picture appears to have a relationship of :HC
the usage if SIZE( ()-[:HS]->(cS) )
will report the number of :HS relationships from a given cS
aliased node to any other node and from the picture :cS
labeled nodes appear to have only 1 relationship.
in the initial match is (rk)
, which basically says match a :d
labeled not via a :IHF
relationship to any other node (regardless of label). Should this instead be (rk:RK)
or similar
So lets say you had
(:rD {id:rd1})-[:IHF]->(:RK)->[:HC]->(:c {id:'c1'})
(:rD {id:rd1})-[:IHF]->(:RK)->[:HC]->(:c {id:'c2'});
then WITH rD, cS, SIZE( ()-[:HS]->(cS) ) AS Csum
is going to evaluate ti
(:rD {id:rd1}), (:c {id:'c1'}), 1
(:rD {id:rd1}), (:c {id:'c2'}), 1
02-15-2021 06:11 PM
sorry @dana.canzano it was a typo mistake the relationship is HC, let me try your suggestion
02-15-2021 05:24 PM
Hi @maziar
I created the data.
CREATE (d:d {name: 'rd'})-[:IHF]->()-[:HS]->(:c {name: 'name1'}),
(d)-[:IHF]->()-[:HS]->(:c {name: 'name2'}),
(d)-[:IHF]->()-[:HS]->(:c {name: 'name3'})
I wrote this Cypher.
MATCH (rD:d)-[:IHF]->(rK)-[:HS]->(cS:c)
RETURN rD.name, collect(cS.name), count(cS.name) AS Csum
I think the return value is something like this.
Is this the answer to your question?
02-15-2021 06:12 PM
Awesome @koji it seems it is working but let me include it in the main story and I will get back to you, thank you so much
All the sessions of the conference are now available online