我正在使用 Python 驱动程序来使用 Neo4j。我已经连接到本地主机
URI = "neo4j://localhost:7687"
AUTH = ("neo4j", "neo4j")
with GraphDatabase.driver(URI, auth=AUTH) as driver:
driver.verify_connectivity()
driver: Driver = GraphDatabase.driver(URI, auth=AUTH)
现在我想将结果显示为一些查询的图表,如下所示:
query = 'MATCH (n)-[r]->(c) where r.filePath = "../data/mydata.json" RETURN *'
driver.execute_query(query)
据我了解,python 驱动程序不直接与 neo4j 浏览器交互。 那么显示结果图的最佳方式是什么?
您希望代码流式传输什么? Cypher 查询没有 RETURN 子句。
尝试检查从
EagerResult
返回的 execute_query
对象的摘要。这是一个例子
from neo4j import GraphDatabase
URI = "neo4j://localhost:7687"
AUTH = ("neo4j", "neo4j")
with GraphDatabase.driver(URI, auth=AUTH) as driver:
driver.verify_connectivity()
result = driver.execute_query(
"CREATE (charlie:Person:Actor {name: 'Charlie Sheen'})"
"-[:ACTED_IN {role: 'Bud Fox'}]->"
"(wallStreet:Movie {title: 'Wall Street'})"
"<-[:DIRECTED]-"
"(oliver:Person:Director {name: 'Oliver Stone'})"
)
print(result.summary.counters)
这给了我
{'_contains_updates': True, 'labels_added': 5, 'relationships_created': 2, 'nodes_created': 3, 'properties_set': 4}
所以它显然在做某事。
如果这不起作用,启用驱动程序的调试日志记录以查看它的情况会很有帮助。 API 文档中有一节介绍了如何执行此操作:https://neo4j.com/docs/api/python-driver/current/api.html#logging
最简单的形式是这样的
from neo4j.debug import watch
watch("neo4j")
# from now on, DEBUG logging to stderr is enabled in the driver