Search code examples
pythonneo4jpy2neo

Passing node object as parameter in graph query Py2neo


I have the following code in which I am obtaining a node. How can I pass it to graph.evaluate as a parameter. Is there a possible method to do so if this is incorrect ? Or some alternative method

user_node = selector.select("User", user_id=95)
lib_node = graph.evaluate("match {param}-[:LISTENS_TO]->(p) return p", param=dict(user_node))

the above throws value error

ValueError: dictionary update sequence element #0 has length 6; 2 is required

Solution

  • The select method returns a selection of as many matches as it can find. This may or may not be a sequence of one but either way, you'll need to use the .first() method to grab the first (and probably only) one returned.

    http://py2neo.org/v3/database.html#py2neo.database.selection.NodeSelection.first