简体   繁体   English

neo4j BOLT驱动程序中的py2neo命令

[英]py2neo command in neo4j BOLT driver

I have a command written in python using the py2neo to access the name of an exchange. 我有一个使用py2neo用python编写的命令来访问交换的名称。 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? 可以将其转换为BOLT neo4j-driver语句吗? I always get an error. 我总是会出错。 I want to avoid an iterator statement where I loop through the StatementResult. 我想避免在StatementStatement中循环的迭代器语句。

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

Try to store the results of session.run() in a list to retain them: 尝试将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]

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM