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 number of relationships per type

m-kiuchi
Node Clone

Let me take simple question. I'm counting the number of nodes and relationships per labels and types. I successfully can count nodes like this query.

CALL db.labels() YIELD label
CALL apoc.cypher.run('MATCH (:`'+label+'`) RETURN count(*) as count',{}) YIELD value
RETURN label, value.count

Along with above query, I compiled query to count relationships per types like this, but it not works. Every value.count shows 0.

CALL db.relationshipTypes() YIELD relationshipType
CALL apoc.cypher.run('MATCH ()-[r:`]'+relationshipType+'`]-() RETURN count(*) as count', {}) YIELD value
RETURN relationshipType, value.count

Please point out my mistake... Thanks to have your time.

1 ACCEPTED SOLUTION

You have an extra closing square bracket for the relationship in your string, you can remove that:

'MATCH ()-[r:'+relationshipType+']-() RETURN count(*) as count'

That said, you can get pretty much everything you need via APOC which can dump the count store values:

CALL apoc.meta.stats()

View solution in original post

2 REPLIES 2

You have an extra closing square bracket for the relationship in your string, you can remove that:

'MATCH ()-[r:'+relationshipType+']-() RETURN count(*) as count'

That said, you can get pretty much everything you need via APOC which can dump the count store values:

CALL apoc.meta.stats()

Thanks much for pointing my mistake and useful APOC function !