Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-05-2022 04:37 AM
Hi I'm currently using DBMS version 5.1.0
MY data model is (:User)-[:LIKE]->(:Pull)
I'm trying to count the number of likes relationship for a specific Pull using this query
PROFILE
MATCH res=(:Pull {id:"pull4"})-[:LIKE]-()
return size(collect(relationships((res)))) as res
MATCH (p:Pull {id:"pull4"})
RETURN size( (p)-[:LIKE]-() )
Error:
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. No other uses are allowed, instead they should be replaced by a pattern comprehension. (line 2, column 15 (offset: 43))
"RETURN size( (p)-[:LIKE]-() )"
Query-2:
MATCH (p:Pull {id:"pull4"})
RETURN length( (p)-[:LIKE]-() )
Error:
Type mismatch: expected Path but was List<Path> (line 2, column 17 (offset: 45))
"RETURN length( (p)-[:LIKE]-() )"
Is there a way of counting without the need to expand all like this question https://community.neo4j.com/t5/neo4j-graph-platform/count-store-where-clause-workaround/m-p/18298#M7... but its answer is my query-1 and it fails
Solved! Go to Solution.
11-05-2022 01:11 PM
MATCH (p:Pull {id:"pull4"}) RETURN size( [ (p)-[:LIKE]-() ] | p )
Which uses pattern comprehension and described in 4x and 5x cypher manual
11-05-2022 01:11 PM
MATCH (p:Pull {id:"pull4"}) RETURN size( [ (p)-[:LIKE]-() ] | p )
Which uses pattern comprehension and described in 4x and 5x cypher manual
11-05-2022 03:29 PM
MATCH (p:Pull {id:"pull4"}) RETURN size( [ (p)-[:LIKE]-() ] | p ) this throwed an error
MATCH (p:Pull {id:"pull4"}) RETURN size( [ (p)-[:LIKE]-() | p] ) this worked
Thank you for your help but I have another question:
I found another answer using apoc and it has less db hits using this query:
All the sessions of the conference are now available online