This question is a follow on to the question here
I have a graph that has a circular linked list. (see here for an example) Each node in the linked list points to a User. When querying the list I have to use a path statement as the list is circular and I do not want to retrieve nodes beginning from the u:USER node. In order to get the nodes of interest my query looks like this:
MATCH path=(nl:NODELINK { linkId:'cc' })-[:LINK*]->(u:USER)
RETURN nodes(path)
Once I have retrieved the path I would like to do further matching against the nodes in that path (the NODELINK's), somthing like the following:
MATCH path=(nl:NODELINK { linkId:'cc' })-[:LINK*]->(u:USER)
WITH nodes(path) AS nodeLinks
MATCH nodeLinks-[:PERSONLINK]->persons
RETURN persons
but if I try I get an error:
Error: Type mismatch: nodeLinks already defined with conflicting type Collection<Node> (expected Node) (line 3, column 7)
"MATCH nodeLinks-[:PERSONLINK]->persons"
How do I unpack the nodes of type NODELINK from the path in order to do further MATCH queries against them?
Try this one... kind of hacky but until there's an unwind operation, it will work.
MATCH path=(nl:NODELINK { linkId:'cc' })-[:LINK*]->(u:USER)
WITH [x in nodes(path) | id(x)] AS nodeLinkIds
MATCH (n1:NODELINK)
WHERE id(n1) in nodeLinkIds // this does efficient id lookups for the nodes in the list
MATCH n1-[:PERSONLINK]->persons
RETURN persons
There's now an UNWIND
operator, so this should work:
MATCH path=(nl:NODELINK { linkId:'cc' })-[:LINK*]->(u:USER)
WITH nodes(path) AS x UNWIND x AS nodeLinks
MATCH nodeLinks-[:PERSONLINK]->persons
RETURN persons
I'd have thought we could do WITH UNWIND nodes(path) AS nodeLinks
, but that gives me a cryptic Conversion = '''
error in Neo4j 2.2.0-M03.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With