Best way to mass-insert Edges into ArangoDB?

208 Views Asked by At

I'm writing a python converter for Neo4J to ArangoDB and expect +10k Nodes to be imported. The converter for the Nodes is somewhat trivial but the creator of that database has a rather custom key-setting so I can't export his keys from his Neo4J instance but I know the name of the PK-Field.

That give me multiple approaches to set the Edges. Right now I'm getting the correct _key of the nodes in the ArangoDB-Collection of the from/to and insert a new edge (code below).

Theoretically I could write the AQL-Statements that just insert these edges, but is that more efficient?

Is there a better approach than my current one?

def getLinkN4jNodes(au,relationships,keyname,col,ecol):
    
    for relationship in relationships:
        startnode = relationship.start_node
        endnode=  relationship.end_node
        sn_key=dict(startnode)[keyname]
        en_key=dict(endnode)[keyname]

        a_sn = au.getNodesFromDB(col,keyname,sn_key)# f"FOR doc IN {col} FILTER doc.`{keyname}`== '{sn_key}' RETURN doc"
        a_en = au.getNodesFromDB(col,keyname,en_key)
        
        newedge={
            "_key":a_sn["_key"]+'_'+a_en["_key"],
            "_from":a_sn["_key"],
            "_to": a_en["_key"]
        }
        
        ecol.insert(newedge)
0

There are 0 best solutions below