0

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)
Qohelet
  • 1,459
  • 4
  • 24
  • 41
  • I would not write AQL to insert individual documents, nodes or edges. Use the bulk import support of the python arango driver: https://stackoverflow.com/questions/61345323/bulk-import-of-json-files-in-arangodb-with-python#61437353 – Tom Regner Jul 05 '22 at 09:15
  • @TomRegner - this would imply I have a JSON. In order to get a JSON I would have to parse the relationships into a JSON first and then read the JSON. That's an additional step I would like to avoid – Qohelet Jul 05 '22 at 11:33
  • The batch api documentation of python-arango is found here: https://docs.python-arango.com/en/main/batch.html; it speeds up the insert by reducing http overhead - in case of small documents such as yours, this can make quite the difference. – Tom Regner Jul 06 '22 at 07:14
  • @TomRegner - that's part of my question too. The sample you referred to is used for documents. Can it be also used for edges? – Qohelet Jul 06 '22 at 08:00
  • Yes, edge-collections are special but basically normal collections with a few constraints - I use the batch-API regularly (not from python, but that shouldn't make a difference) when creating graphs representing questionnaires and decision trees. – Tom Regner Jul 06 '22 at 08:50

0 Answers0