I have a graph
in ArangoDB. How to create edge with specified _key
value? My code:
edge_attributes = {"_key": "ab", "count": 0}
graph.createEdge(collection_edges_name, node_from_id, node_to_id, edge_attributes)
I can see proper values of count
as well as _from
and _to
, but _key
is some random number.
How I can create an edge with a specific _key
? I want to specify key to fast querying edges by key as well as preventing multiple edges from node A to node B.
I prepared a workaround for this problem. I create an instance of Edge class with a specified name of the collection with edges and then I call:
edge_attributes = {"_key": edge_key,
"_from": parent_id,
"_to": node_to_id,
"count": 0}
edge = my_edges_collection.createDocument(edge_attributes)
edge.save()
This solution creates a document with the proper key and id.