【发布时间】:2019-08-03 18:46:05
【问题描述】:
你好,我是 python 中的 neo4j(neo4j-driver) 的新手。检查节点是否不存在时出现问题,我通过这些代码发送了一些与数据库中的节点不匹配的名称。
from neo4j import GraphDatabase
driver = GraphDatabase.driver('bolt://localhost:7687', auth=(user, pass))
session = driver.session()
def matchNode(name):
Label = 'SINGLE_NODE'
return session.run("MATCH (a:"+Label+") WHERE a.name= $name "
"RETURN id(a)", name=name).single().value()
name = 'test'
nodeID = matchNode(name)
if nodeID:
print("Exist")
else:
print("Not Exist")
但它会出现这样的错误,因为它没有与 db 中的节点匹配。
Traceback (most recent call last):
File ".\neo4jdriver.py", line 44, in <module>
props = matchNode(driver,'test')
File ".\neo4jdriver.py", line 25, in matchNode
"RETURN id(a)", name=name).single().value()
AttributeError: 'NoneType' object has no attribute 'value'
Failed to write data to connection Address(host='localhost', port=7687) (Address(host='127.0.0.1', port=7687)); ("0; 'Underlying socket connection gone (_ssl.c:2263)'")
Failed to write data to connection Address(host='localhost', port=7687) (Address(host='127.0.0.1', port=7687)); ("0; 'Underlying socket connection gone (_ssl.c:2263)'")
Failed to write data to connection Address(host='localhost', port=7687) (Address(host='127.0.0.1', port=7687)); ("0; 'Underlying socket connection gone (_ssl.c:2263)'")
Failed to write data to connection Address(host='localhost', port=7687) (Address(host='127.0.0.1', port=7687)); ("0; 'Underlying socket connection gone (_ssl.c:2263)'")
Failed to write data to connection Address(host='localhost', port=7687) (Address(host='127.0.0.1', port=7687)); ("0; 'Underlying socket connection gone (_ssl.c:2263)'")
那么如果节点不存在,我该如何解决这个问题并且不返回任何内容。谢谢
【问题讨论】:
标签: python neo4j neo4j-bolt neo4j-driver