pyArango - 使用指定的_key创建边

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

我在ArangoDB中有一个graph。如何使用指定的_key值创建边缘?我的代码:

edge_attributes = {"_key": "ab", "count": 0}
graph.createEdge(collection_edges_name, node_from_id, node_to_id, edge_attributes)

我可以看到count以及_from_to的正确值,但_key是一些随机数。

我如何用特定的_key创建边缘?我想指定按键快速查询边缘的键,以及防止从节点A到节点B的多个边缘。

python graph arangodb pyarango
1个回答
0
投票

我为这个问题准备了一个解决方法。我创建了一个Edge类的实例,其中包含带边的集合的指定名称,然后我调用:

edge_attributes = {"_key": edge_key,
                   "_from": parent_id,
                   "_to": node_to_id,
                   "count": 0}
edge = my_edges_collection.createDocument(edge_attributes)
edge.save()

此解决方案使用正确的密钥和ID创建文档。

© www.soinside.com 2019 - 2024. All rights reserved.