Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-24-2022 10:59 PM
Hi all,
I have a list of Products and Persons. A Product can have relationships to different Persons, such as "hasProductOwner", "hasDeveloper", "hasTechnicalWriter", etc. (these are effectively roles that a person can have for a Product).
A Person can have multiple roles for the same Product or across different Products.
I want to find the Person with the most roles across all Products (i.e. the count), as well as I want to list all the roles that this person has against which product.
I am running this query, which gets me the results, but a) it says it's deprecated and b) how do I filter that I only want to count relationship between Product and Person of a certain type (e.g. only "hasProductOwner", "hasDeveloper", "hasTechnicalWriter") ?
This gives me the count
Solved! Go to Solution.
10-25-2022 01:52 AM
Thanks for your answer!
I read a bit more about the collect() function and ended up writing this, which works well.
MATCH (pr:Product)-[r]->(pe:Person)
WITH pe, collect({role:type(r), product: pr.uri}) as rolesOnProducts, count(r) as roleCount
RETURN pe.lastName as "Last Name", roleCount, rolesOnProducts
ORDER BY roleCount DESC
Best regards
10-25-2022 01:27 AM - edited 10-25-2022 01:28 AM
Hello @argytzak 🙂
MATCH path=(product:Product)-[r*0..1]-(person:Person)
WITH person, [relationship IN relationships(path) | type(relationship)] AS types
RETURN person.lastName, types
Regards,
Cobra
10-25-2022 01:52 AM
Thanks for your answer!
I read a bit more about the collect() function and ended up writing this, which works well.
MATCH (pr:Product)-[r]->(pe:Person)
WITH pe, collect({role:type(r), product: pr.uri}) as rolesOnProducts, count(r) as roleCount
RETURN pe.lastName as "Last Name", roleCount, rolesOnProducts
ORDER BY roleCount DESC
Best regards
All the sessions of the conference are now available online