0

I have a command written in python using the py2neo to access the name of an exchange. This works.

graph = Graph()
stmt = 'MATCH (i:Index{uniqueID: 'SPY'})-[r:belongsTo]->(e:Exchange) RETURN e.name'
exchName = graph.cypher.execute(stmt)[0][0]

Can this be converted to a BOLT neo4j-driver statement? I always get an error. I want to avoid an iterator statement where I loop through the StatementResult.

driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"))
session = driver.session()
stmt = 'MATCH (i:Index{uniqueID: 'SPY'})-[r:belongsTo]->(e:Exchange) RETURN e.name'
exchName = session.run(stmt)[0][0]
TypeError: 'StatementResult' object is not subscriptable
Goofball
  • 735
  • 2
  • 9
  • 27

1 Answers1

1

Try to store the results of session.run() in a list to retain them:

driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"))
session = driver.session()
stmt = 'MATCH (i:Index{uniqueID: 'SPY'})-[r:belongsTo]->(e:Exchange) RETURN e.name'

# transform to list to retain result
exchName = list(session.run(stmt))[0][0]

See the docs: http://neo4j.com/docs/developer-manual/current/#result-retain

Martin Preusse
  • 9,151
  • 12
  • 48
  • 80