Hey
py2neo for the moment, But trying to build most of the stuff via queries. In any case, I'm struggling with this code... How can I properly and efficiently create 100k+ relationships?
# My getter to return list of nodes
def getNodesByType(type, limit=-1):
if limit > 0:
a = graph.run('''
MATCH (n:{type})
RETURN n
LIMIT {limit}'''.format(type=type, limit=limit))
return a
return graph.run('''
MATCH (n:{type}}
RETURN n'''.format(type=type))
def makeConnection(source, key, dest):
tx = graph.begin()
tx.run('''
UNWIND $arrSource AS mSrc
CALL apoc.create.relationship(mSrc,{k}, {d})
YIELD node
RETURN node
'''
, arrSource=source, k=key, d=dest)
tx.commit()
nodeA = getNodesByType("Pets", 10).to_ndarray()
nodeB= getNodesByType("Objects", 3).to_ndarray()
makeConnection(nodeA,"livesIn",nodeB[0])
makeConnection(nodeA[0:5000],"livesNextTo",nodeB[1])
makeConnection(nodeA[50000:99999],"livedIn",nodeB[2])
I keep on getting
TypeError: Neo4j does not support JSON parameters of type ndarray
I'm lost, I mean I'm passing Node object to it, so maybe thats wrong? How should I execute this task ?
Regards
Dariusz
Edit now that I look at it, I'm not sure if I can use the apoc as I need CREATE UNIQUE
as I want to only create a relationship if it's missing.