Showing results for 
Search instead for 
Did you mean: 

Nodes(path) returns the node graph, NOT a list

Node Clone

I'm trying to represent Enigma rotors with neo4j.

match (input:Input{IN:"A"}) match path=(n:Rotor1{IN:input.IN})-[*]-(m) return input,nodes(path)

returns the connected nodes, but never a list. Is it because the path is not oriented?
How can I extract the "last" node (F),i.e. the coding of (A) with these settings.


You can adjust how you want to review the results on the left side of the result pane. Currently you're viewing the graph result view. You can view the Table result view below and you should see, per row, your input node followed by a list of the nodes in the path for that row.

As far as the "last" node, that depends upon what defines a last node.

Is it that there should be no other relationships aside from the one you traversed to get to the node? In that case you should add WHERE size((m)--()) = 1.

Is it the node at furthest distance from n? In that case order the paths by length descending and limit:

WITH input, path
ORDER BY length(path) DESC
RETURN input, nodes(path)

If there's some other criteria then you'll have to figure out how to include that in your query.

thank you Andrew, my final code for the furthest distance:

match (input:Input{IN:"A"}) match path=(n:Rotor1{IN:input.IN})-[*]-(m) WITH input, path
ORDER BY length(path) DESC
with input, nodes(path)[length(path)] as result
match(output:Output) where output.IN=result.IN
RETURN input,output

gives the result:
BTW, it's the Enigma coding for "A" with rotors III,II,I, rings A,A,A, no plugboard

Nodes 2022
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.