Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-06-2018 08:59 AM
All what I need is knowing how many times each node collaborated with other nodes , I found this example and I followed it .
I runned this query :
MATCH (n:Attributaires)-[r:CollaborateWith]->(m:Attributaires)
With distinct n.id as Attributaires , size((n)-->(m)) AS NumberOfRelations , m.id AS Collaborators
RETURN Attributaires , NumberOfRelations , Collaborators
But I am getting the same value for all "NumberOfRelations" which is "1" .
Anyone has a solution and could help please ?
Solved! Go to Solution.
11-06-2018 10:07 AM
Based on the example you reference your issue my be with size((n)-->(m))
.
In the example, @Benoit uses size((n)-->())
. In this example leaving the second node "emtpy" ()
lets you count all of those that are connected. However, in your example, using (m)
means you are only counting the relationships between (m)
and (n)
. Unless you have multiple relationships connecting these nodes, you will always get "1".
Try using
MATCH (n:Attributaires)-[r:CollaborateWith]->(m:Attributaires)
With distinct n.id as Attributaires , size((n)-->()) AS NumberOfRelations , m.id AS Collaborators
RETURN Attributaires , NumberOfRelations , Collaborators
11-06-2018 10:07 AM
Based on the example you reference your issue my be with size((n)-->(m))
.
In the example, @Benoit uses size((n)-->())
. In this example leaving the second node "emtpy" ()
lets you count all of those that are connected. However, in your example, using (m)
means you are only counting the relationships between (m)
and (n)
. Unless you have multiple relationships connecting these nodes, you will always get "1".
Try using
MATCH (n:Attributaires)-[r:CollaborateWith]->(m:Attributaires)
With distinct n.id as Attributaires , size((n)-->()) AS NumberOfRelations , m.id AS Collaborators
RETURN Attributaires , NumberOfRelations , Collaborators
11-06-2018 11:41 AM
I think you can simplify you query:
MATCH (n:Attributaires)-[r:CollaborateWith]->(m:Attributaires)
WITH n.id as Attributaires , m.id AS Collaborators, count(*) AS NumberOfRelations
RETURN Attributaires , NumberOfRelations , Collaborators
All the sessions of the conference are now available online