Count number of relationships per type

(M Kiuchi) #1

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'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'MATCH ()-[r:`]'+relationshipType+'`]-() RETURN count(*) as count', {}) YIELD value
RETURN relationshipType, value.count

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

(Andrew Bowman) #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()

(M Kiuchi) #3

Thanks much for pointing my mistake and useful APOC function !