我在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类的实例,其中包含带边的集合的指定名称,然后我调用:
edge_attributes = {"_key": edge_key,
"_from": parent_id,
"_to": node_to_id,
"count": 0}
edge = my_edges_collection.createDocument(edge_attributes)
edge.save()
此解决方案使用正确的密钥和ID创建文档。