One thing that I have come across when using Neo4j for social media projects is how can I get multiple aggregate data with one cypher query. For example I want to know the number of followers a user has and the number of friends they are following.
START user = node(2065) OPTIONAL MATCH (user)<-[:following]-(followers:User) OPTIONAL MATCH (user)-[:following]->(friends:User) RETURN COUNT(DISTINCT followers) as numberOfFollowers, COUNT(DISTINCT friends) as numberOfFriends;
The reason we use
DISTINCT is just in case you have multiple or relationships.
OPTIONAL MATCH (user)<-[:followingPublished|:followingPersonal]-(followers:User)
This way the count is always correct and with duplicates.