py2neo create function creating duplicate nodes
我有一个包含国会议员信息的 Neo4j 数据库。我遇到的问题是是否有空缺职位。发生这种情况时,我在"Congressmen"索引中使用相同的键:值。我尝试了下面的代码,因为在 py2neo 文档中它声明 add 函数是幂等的
1 2 3 4 5 6 7 8 9 10 11 12 | #Check if we have any vacancies and if so if they match the one that we currently want to add query="start n=node:Congressmen('website:N/A') return n" result= cypher.execute(graph_db, query.encode('utf-8', errors='ignore')) #Match what we already have if str(result[0]) !="[]": #create is idempotent so will only create a new node if properties are different rep, = graph_db.create({"name" : userName,"website" : web,"district" : int(district),"state" : child[2].text,"party" : child[4].text,"office" : child[5].text,"phone" : child[6].text,"house" :"House of Representatives"}) cong = graph_db.get_or_create_index(neo4j.Node,"Congressmen") # add the node to the index cong.add("website", web, rep) |
当我在运行代码 3 次后检查界面时,我有重复的节点。
是否可以防止节点重复并仍然能够使用相同的键/值对它们进行索引?