使用Python neo4j-restclient
,我试图找出是否可以简化从同一节点发送到不同节点的相同关系的创建。所以目前,我有
alice = g.nodes.create(name='Alice')
bob = g.nodes.create(name='Bob')
chuck = g.nodes.create(name='Chuck')
darryl = g.nodes.create(name='Darryl')
eve = g.nodes.create(name='Eve')
alice.relationships.create("is friends with", bob)
alice.relationships.create("is friends with", chuck)
alice.relationships.create("is friends with", darryl)
alice.relationships.create("is friends with", eve)
有没有更简单的方法可以做到这一点,而不必多次调用relationships.create
?
答案 0 :(得分:0)
我会使用Cypher查询或基于批处理的事务。
with g.transaction():
alice = g.nodes.create(name='Alice')
for name in ["Bob","Chuck","Darryl","Eve"]:
friend = g.nodes.create(name=name)
alice.relationships.create("is friends with", friend)
甚至没有交易。