pyArango - 使用指定的 _key 创建边缘

pyArango - create edge with specified _key

我在 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 的多个边。

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

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

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