I have a linked list that is modelled in a circular fashion like so:
(u:User)
-[:LINK]->(a:NODELINK {linkId: 'aa'})
-[:LINK]->(b:NODELINK {linkId: 'bb'})
-[:LINK]->(c:NODELINK {linkId: 'cc'})
-[:LINK]->(d:NODELINK {linkId: 'dd'})
-[:LINK]->(u)
When I query it starting at node (b:NODELINK {linkId: 'bb'})
I would like to match all nodes until I get to the end/start of the list. (The User node)
When I run the following query:
MATCH (u:USER)
WITH u
MATCH (nl:NODELINK)-[:LINK*]->(m)
WHERE nl.linkId = 'bb' AND m <> u
RETURN m
It returns me the following nodes
(3:NODELINK {linkId:'cc'})
(4:NODELINK {linkId:'dd'})
(1:NODELINK {linkId:'aa'})
(2:NODELINK {linkId:'bb'})
As you can see my query wraps around and starts returning nodes from the start of the list. I would like to terminate at the User node and only return the nodes before the end of the list
(3:NODELINK {linkId:'cc'})
(4:NODELINK {linkId:'dd'})
I have created a graph that demonstrates the issue here
How do I query so as to start at the node link of interest and returns all nodes before it reaches the User node?