I'm not sure what this error means!

Kinda related to my last post, but when I try this call:

MATCH (m:Drug {id: 'A'})-[:CONTAINS*2..2]-(neighbors) 
return neighbors.id, collect(r1.weight) as weight order by weight desc

I get this error:

Neo.ClientError.Statement.SyntaxError: Type mismatch: expected Any, Map, Node, 
Relationship, Point, Duration, Date, Time, LocalTime, LocalDateTime or DateTime 
but was List<Relationship> (line 1, column 86 (offset: 85))
"MATCH (m:Drug {id: 'A'})-[r1:CONTAINS*2..2]-(neighbors) 
return neighbors.id, collect(r1.weight) as weight order by weight desc"

Is there a reason why I can't order by weight here?
Thx :slight_smile:

Because you're using a variable-length relationship, r1 refers to a 2-element collection, the two relationships traversed between the two nodes.

If you want the sum of those two relationships per row, then you can use:

WITH m, neighbors, reduce(sum = 0, rel in r1 | sum + rel.weight) as weight
WITH neighbors, sum(weight) as total
RETURN neighbors.id, total

If you want the collection of those sums then do a collect(weight) in that WITH clause as well.

For reference, reduce() operates on a list on a row (in this case summing the two weights in the relationships), and you could alternately use apoc.coll.sum() if you have APOC Procedures to do this.
sum() and collect() are aggregation functions that do aggregations across multiple rows per your grouping key.