簡體   English   中英

neo4j BOLT驅動程序中的py2neo命令

[英]py2neo command in neo4j BOLT driver

我有一個使用py2neo用python編寫的命令來訪問交換的名稱。 這可行。

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語句嗎? 我總是會出錯。 我想避免在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

嘗試將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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM