cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

count store expand all problem

moneeb
Node Link

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 
the problem is I'm expanding all the nodes and then accessing the count store I've tried all the below queries:
Query-1:  
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

1 ACCEPTED SOLUTION

@moneeb 

 

MATCH (p:Pull {id:"pull4"}) RETURN size( [ (p)-[:LIKE]-() ] | p )

 

Which uses pattern comprehension and described in 4x and 5x cypher manual

View solution in original post

2 REPLIES 2

@moneeb 

 

MATCH (p:Pull {id:"pull4"}) RETURN size( [ (p)-[:LIKE]-() ] | p )

 

Which uses pattern comprehension and described in 4x and 5x cypher manual

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:

profile
MATCH (p:Pull {id:"pull4"})
// Get all relationship types for a given node
UNWIND apoc.node.relationship.types(p) as type
WITH p,
     type,
     // Get the incoming degree value for the relationship type
     apoc.node.degree.in(p, type) as count
 
it counts all relation ships separately with less db hits but both uses the node degree don't know why there is a diffrence.