neo4j BOLT 驱动程序中的 py2neo 命令

py2neo command in neo4j BOLT driver

我有一个用 python 编写的命令,使用 py2neo 访问交易所的名称。这行得通。

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

这可以转换为 BOLT neo4j-driver 语句吗?我总是得到一个错误。我想避免循环遍历 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

尝试将 session.run() 的结果存储在 list 中以保留它们:

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]

查看文档:http://neo4j.com/docs/developer-manual/current/#result-retain