如何获取neo4j查询中更新的节点总数?

问题描述 投票:0回答:1

在python中运行cypher查询后,我想获得通过查询更新的节点数。我该怎么办呢?

python neo4j
1个回答
0
投票

如果你使用Neo4j Bolt Driver 1.6 for Python,你需要consume函数:

print(session.run("MERGE (a:TEST {name: rand()})").consume().counters)

// {'labels_added': 1, 'nodes_created': 1, 'properties_set': 1}

更新:如果您使用旧库neo4jrestclient(不再积极开发),则使用变量stats(并指定选项data_contents=True):

print(gdb.query("MERGE (a:TEST {name: rand()})", data_contents=True).stats)
// {u'relationship_deleted': 0, u'constraints_added': 0, u'labels_added': 1, 
// u'labels_removed': 0, u'nodes_created': 1, u'properties_set': 1, u'nodes_deleted': 0, 
// u'constraints_removed': 0, u'indexes_removed': 0, u'contains_updates': True, 
// u'relationships_created': 0, u'indexes_added': 0}
© www.soinside.com 2019 - 2024. All rights reserved.