Rob
Rob

Reputation: 3499

Neo4j cypher for all nodes connected to list of values, get sum of relationship parameters

So I'm still learning how to access relationship parameters, I've found several ways to access different aspects of what I'm looking for but can't seem to piece it together.

neo4j cypher - how to find all nodes that have a relationship to list of nodes

I am getting closer, but can't figure out how to sum a collection and check for length.

MATCH (album:Album)-[r]->(tags:Word)
WHERE tags.name IN ['alpha', 'bravo']
WITH album, COLLECT(tags) as tags, COLLECT(r.weight) as weight
RETURN album, tags, weight

Thank you in advance.

Upvotes: 0

Views: 534

Answers (1)

Rob
Rob

Reputation: 3499

Ok so I found a solution to avoid the COLLECTION issue, apparently anywhere that you collect you can also sum. I'm learning though and enjoying the process!

MATCH (album:Album)-[r]->(tags:Word) 
WHERE tags.name IN ['alpha', 'bravo']
WITH album, COLLECT(tags) as tags, SUM(r.weight) as weight
WHERE LENGTH(tags) = LENGTH(['alpha', 'bravo'])
RETURN album, tags, weight ORDER BY weight ASC LIMIT 10;

Upvotes: 2

Related Questions