cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Exclude node with specific label from returned paths

Hi,

I can't figure out how to exclude some nodes from the return paths of my query, the goal here is reduce the number of possible paths and thus execution time.
The original query:
MATCH r=(u:User {displayName:"User1"})-[*5..6]->(a:Application {displayName:"App1"}) RETURN r

One the path returned is:
(User1)-[ HasRole]->(Role1)-[HasPermissionsOn]->(Role1)-[HasPermissionsOn]->(Role2)-[HasPermissionsOn]->(User2)-[HasRole]->(Role3)-[HasPermissionsOn]->(App1)

Is there a way to change the query to remove the possibility of having another User in the path ?

Thanks

1 REPLY 1

anthapu
Graph Fellow

You can try the Cypher List expressions here.

Try the query like this

MATCH r=(u:User {displayName:"User1"})-[*5..6]->(a:Application {displayName:"App1"}) 
WITH r, [x in nodes(r) WHERE x:User AND id(x) <> id(u) | x] as otherUsers
WITH r
WHERE size(otherUsers) = 0 
RETURN r