2

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.

wind
  • 892
  • 1
  • 11
  • 27

1 Answers1

2

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.

wind
  • 892
  • 1
  • 11
  • 27
  • Hi @wind, is it possible to create edge base on values instead of id, say I have two document collections, each has 'ID' field, if the 'ID' in one record of one document matches with 'ID' of one record in another document, we should create an edge, may I know is it possible please – hanzgs Nov 28 '19 at 04:38