我目前正在开发ArangoDB POC。我发现使用PyArango在ArangoDB中创建文档所需的时间非常长。插入300个文档大约需要5分钟。我已粘贴下面的粗略代码,如果有更好的方法可以加快速度,请告诉我:
with open('abc.csv') as fp:
for line in fp:
dataList = line.split(",")
aaa = dbObj['aaa'].createDocument()
bbb = dbObj['bbb'].createDocument()
ccc = dbObj['ccc'].createEdge()
bbb['bbb'] = dataList[1]
aaa['aaa'] = dataList[0]
aaa._key = dataList[0]
aaa.save()
bbb.save()
ccc.links(aaa,bbb)
ccc['related_to'] = "gfdgf"
ccc['weight'] = 0
ccc.save()
不同的集合由以下代码创建:
dbObj.createCollection(className='aaa', waitForSync=False)
答案 0 :(得分:4)
了解arango java驱动程序中批处理模式的问题。如果您知道顶点的关键属性,则可以通过" collectionName"来构建文档句柄。 +" /" +" documentKey"。 例如:
arangoDriver.startBatchMode();
for(String line : lines)
{
String[] data = line.split(",");
BaseDocument device = new BaseDocument();
BaseDocument phyAddress = new BaseDocument();
BaseDocument conn = new BaseDocument();
String keyDevice = data[0];
String handleDevice = "DeviceId/" + keyDevice;
device.setDocumentKey(keyDevice);
device.addAttribute("device_id",data[0]);
String keyPhyAddress = data[1];
String handlePhyAddress = "PhysicalLocation/" + keyPhyAddress;
phyAddress.setDocumentKey(keyPhyAddress);
phyAddress.addAttribute("address",data[1]);
final DocumentEntity<BaseDocument> from = arangoDriver.graphCreateVertex("testGraph", "DeviceId", device, null);
final DocumentEntity<BaseDocument> to = arangoDriver.graphCreateVertex("testGraph", "PhysicalLocation", phyAddress, null);
arangoDriver.graphCreateEdge("testGraph", "DeviceId_PhysicalLocation", null, handleDevice, handlePhyAddress, null, null);
}
arangoDriver.executeBatch();
答案 1 :(得分:0)
我将构建要插入json格式字符串的所有数据,并使用createDocumentRaw一次创建所有数据,只需一次保存。