1

In python code I get a list of uids of nodes f.e. [1,2,3].

I want to build a query to find a consecutively connected nodes and return the parent.

So in this case the query will look like this:

  match (n0)-->(n1)-->(n2)-->(n3) 
  where n1.uid % 100 = 1 % 100 and n2.uid % 100 = 2 % 100 and n3.uid % 100 = 3 % 100
  return n0 

as you can see this is not very scalable if I use longer lists f.e. [5,3,104,202,....] The query will grow alot.

Is there a shortcut I can use to handle lists of different sizes. Keep in mind that the order of the nodes have to match the data-list.

sten
  • 7,028
  • 9
  • 41
  • 63

1 Answers1

1

You might want to consider constructing your query dynamically from the user input list.

q = "MATCH (n0 {uid:list[0]})"
for id in list[1:]:
    q += "-->({uid:%d})" % id
q += " RETURN n0"

Note code wasn't tested!

SWilly22
  • 869
  • 4
  • 5