Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-22-2020 11:28 AM
Hello people,
I have maybe silly question but regardless..
The query is the following:
MATCH (c:Category)<-[:CATEGORY_PERMISSION]-(p:Permission)
OPTIONAL MATCH (c)<-[:CATEGORY_STRUCTURE]-(child:Category)<-[:CATEGORY_PERMISSION]-(p2:Permission)
RETURN p, p2
I get category and its permissions, then I get children of the category and its permissions.
I want to merge them together when returning and only get distinct values so I have all permissions flattened.
Solved! Go to Solution.
07-22-2020 05:36 PM
If you have apoc plugin installed this is a simple task
MATCH (c:Category)<-[:CATEGORY_PERMISSION]-(p:Permission)
OPTIONAL MATCH (c)<-[:CATEGORY_STRUCTURE]-(child:Category)<-[:CATEGORY_PERMISSION]-(p2:Permission)
WITH collect(p) as firstList, collect(p2) as secondlist
WITH apoc.coll.union(firstList, secondlist) as permissions
UNWIND permissions as permission
RETURN permission
Here I am using unwind to make sure you get permission object as return entity rather than a list.
If you can handle the list you can return the permissions value itself.
07-22-2020 05:36 PM
If you have apoc plugin installed this is a simple task
MATCH (c:Category)<-[:CATEGORY_PERMISSION]-(p:Permission)
OPTIONAL MATCH (c)<-[:CATEGORY_STRUCTURE]-(child:Category)<-[:CATEGORY_PERMISSION]-(p2:Permission)
WITH collect(p) as firstList, collect(p2) as secondlist
WITH apoc.coll.union(firstList, secondlist) as permissions
UNWIND permissions as permission
RETURN permission
Here I am using unwind to make sure you get permission object as return entity rather than a list.
If you can handle the list you can return the permissions value itself.
07-23-2020 08:16 AM
What I could do is also
collect(p) + collect(p2) as all
UNWIND all as single
RETURN distinct single
But I guess union is cleaner since it removes distincts
Thanks a lot
All the sessions of the conference are now available online