What is the cypher to find the no of edges/relationships of each user/node ? I want to return that count for each user.
3 Answers
2
votes
1
votes
The general answer is
MATCH (n)-[r]-()
RETURN n, COUNT(r)
but there are several specifications of this pattern that you are likely to want to make. If you have other nodes than users you may want to limit the query to users by giving them and querying for a label. You may also want to count only a particular type of relationship or only a particular direction, so you add those parts of the pattern as well.
If your users are people and you want to query for how many times each user has called other users on the phone the query might look like
MATCH (n:Users)-[r:CALLED]->(:User)
RETURN n.name as user , COUNT(r) as phone_calls_made
If the [:CALLED]
relationship only ever obtains between users you can drop the second :User
label in the first line.