首页 > 解决方案 > pyArango - 使用指定的 _key 创建边缘

问题描述

graph在 ArangoDB 中有一个。如何创建具有指定_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 的多个边。

标签: pythongrapharangodbpyarango

解决方案


我为这个问题准备了一个解决方法。我使用边缘集合的指定名称创建 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 的文档。


推荐阅读