Get Record Count in Neo4j Graph Database with example
Today in this article, we will see a sample example to Get Record Count in Neo4j Graph Database.
Today in this article, we will cover below aspects,
Please note that the Neo4j node Database maintains a transactional count store for holding count metadata. Due to some reason when you query the count using aggregation functions like count() , the query returns the result immediately.
Let’s take the example below. I have below 2 nodes with the names Movie and Person.
Get the total count from all Nodes
Lets the total count of records available in all nodes
Query
MATCH (n) RETURN count(n) as count
OR
MATCH () RETURN count(*) as count
Above both queries will return the same result.
Example
Get the total count from specific Nodes
Let’s now get the count of records from a specific node like Movie or Person
Que
Query
MATCH (n:Person) RETURN count(n) as count
OR
MATCH (:Person) RETURN count(*) as count
Above both queries will return the same result.
Example
Get the Total Count from specific Nodes using Relationship
As we discuss above Neo4j node Database maintains a transactional count store for holding count metadata. This also includes counting for relationship patterns.
Query
MATCH ()-[r:ACTED_IN]->(:Movie) RETURN count(r) as count
OR
MATCH (:Person)-[r:ACTED_IN]->() RETURN count(r) as count
Example
Useful References :
Do you have any comments or ideas or any better suggestions to share?
Please sound off your comments below.
Happy Coding !!
Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.