我目前正在研究 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()
Run Code Online (Sandbox Code Playgroud)
不同的集合由以下代码创建:
dbObj.createCollection(className='aaa', waitForSync=False)
Run Code Online (Sandbox Code Playgroud) 我使用python-arango作为 ArangoDB 的驱动程序,似乎没有UPSERT接口。
我打算用 python-arango标记它,但我没有足够的代表来创建新标签。
我正在使用如下所示的功能进行管理,但我想知道是否有更好的方法来做到这一点?
def upsert_document(collection, document, get_existing=False):
"""Upserts given document to a collection. Assumes the _key field is already set in the document dictionary."""
try:
# Add insert_time to document
document.update(insert_time=datetime.now().timestamp())
id_rev_key = collection.insert(document)
return document if get_existing else id_rev_key
except db_exception.DocumentInsertError as e:
if e.error_code == 1210:
# Key already exists in collection
id_rev_key = collection.update(document)
return collection.get(document.get('_key')) if get_existing else id_rev_key
logging.error('Could not save document {}/{}'.format(collection.name, document.get('_key'))) …Run Code Online (Sandbox Code Playgroud) 我正在阅读ArangoDB,它更有趣但我无法在文档中找到ArangoDB如何扩展的位置.ArangoDB是否可以扩展,是否可以像MongoDB或CouchDB一样使用分片?
尝试使用ArangoDB Java API创建顶点和边缘而不激活批处理模式,一切正常.但是,启用批处理模式时,它会在创建顶点时抛出未知错误.下面是Java代码和异常详细信息.知道为什么会这样吗?提前致谢!
public static void main(String[] args) throws ArangoException {
createNodesInBatch();
}
static public void createNodesInBatch() throws ArangoException {
ArangoConfigure configure = new ArangoConfigure();
configure.init();
ArangoDriver arangoDriver = new ArangoDriver(configure);
arangoDriver.createDatabase("small_db");
System.out.println("Database created.");
arangoDriver.setDefaultDatabase("small_db");
arangoDriver.createCollection("testEdgeCollection",
new CollectionOptions().setType(CollectionType.EDGE));
arangoDriver.createCollection("testVertexCollection",
new CollectionOptions().setType(CollectionType.DOCUMENT));
EdgeDefinitionEntity ed = new EdgeDefinitionEntity();
// add edge collection name
ed.setCollection("testEdgeCollection");
// add vertex collection names
ed.getFrom().add("testVertexCollection");
// add vertex collection names
ed.getTo().add("testVertexCollection");
List<EdgeDefinitionEntity> edgeDefinitions = new ArrayList<EdgeDefinitionEntity>();
edgeDefinitions.add(ed);
arangoDriver.createGraph("testGraph", edgeDefinitions, null, false);
System.out.println("Graph created.");
arangoDriver.startBatchMode();;
System.out.println("Batch mode …Run Code Online (Sandbox Code Playgroud)