我使用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 enterprise:3.8.6通过Docker. 但不幸的是我的查询花费的时间比30s. 当失败时,错误是arangodb HTTPConnectionPool(host='127.0.0.1', port=8529): Read timed out. (read timeout=60)。
我怎样才能获得包含所有文档的完整集合而不出现任何错误?
Python代码(在我的机器上本地运行)
from arango import ArangoClient
# Initialize the ArangoDB client.
client = ArangoClient()
# Connect to database as user.
db = client.db(<db>, username=<username>, password=<password>)
cursor = db.aql.execute(f'FOR doc IN students RETURN doc', batch_size=10000)
result = [doc for doc in cursor]
print(result[0])
[OUT]
arangodb HTTPConnectionPool(host='127.0.0.1', port=8529): Read timed out. (read timeout=60)
Run Code Online (Sandbox Code Playgroud)
ArangoDB …