Reputation: 39
I can obtain the properties from all the relationships that satisfy a simple pattern (length of 1) such as:
MATCH ()-[r:RELATIONSHIP]->() RETURN collect(r.id)
But cannot obtain the properties of variable length relationships such as:
MATCH ()-[r:RELATIONSHIP*]->() RETURN collect(r.id)
Any help will be appreciated.
Error message is: Neo.ClientError.Statement.SyntaxError: Type mismatch: expected Any, Map, Node, Relationship, Point, Duration, Date, Time, LocalTime, LocalDateTime or DateTime but was List
Upvotes: 2
Views: 3726
Reputation: 4052
In a simple pattern (fixed length 1) variable r
is only one relationship, but in the case of variable length patterns, the variable r
is a list of relationships.
Your first query is correct but in the second query, you are trying to get id property from List
instead of getting it from a particular relationship
.
You can modify your query to get properties from the list as follows:
MATCH ()-[r:RELATED_TO*2]->()
UNWIND r as rel
RETURN COLLECT(DISTINCT id(rel))
Above pattern(Binding relationships to a list in a variable length pattern is deprecated) is deprecated and will be removed in future versions.
The recommended way is to bind the whole path to a variable, then extract the relationships:
MATCH path=()-[:RELATED_TO*2]->()
UNWIND relationships(path) AS rel
RETURN COLLECT(DISTINCT id(rel))
Upvotes: 2