Neo4j 4.3 - Deprecation of size function and pattern comprehension

Viewed 491

In Neo4j 4.3, I get a deprecation warning for the function size with the following text:

A pattern expression should only be used in order to test the existence of a pattern. It should therefore only be used in contexts that evaluate to a boolean, e.g. inside the function exists() or in a WHERE-clause. All other uses are deprecated and should be replaced by a pattern comprehension.

and I have this query:

MATCH (user:User {id: "ffca99b2-0842-491d-b51f-b7c76109e355"})
RETURN user, 
       size((user)-[:FOLLOWS]->(:User)) as numberOfFollowing // This is deprecated

I found a way to make it work without the deprecation that I find quite uglier than the previous one.

MATCH (user:User {id: "ffca99b2-0842-491d-b51f-b7c76109e355"})
RETURN user, 
       size([(user)-[:FOLLOWS]->(other:User) | user]) as numberOfFollowing // No more deprecation

My question is: Is that the only way to get the size of a pattern anymore, or is there a better way? I haven't found any documentation about it, and the official documentation does not say that size is deprecated: https://neo4j.com/docs/cypher-manual/current/functions/scalar/#functions-size-of-pattern-expression

2 Answers

I think SIZE(COLLECT (other)) also works

The new syntax offers a lot more possibilities, because you can combine it with WHERE clause and you can also avoid OPTIONAL MATCH in many cases.

Related