标签: python-arango

带有用于 ArangoDB 的 python-arango 驱动程序的 UPSERT

我使用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)

python-3.x arangodb python-arango

5
推荐指数
1
解决办法
809
查看次数

ArangoDB 读取超时(读取超时=60)

我有个问题。我正在使用ArangoDB enterprise:3.8.6通过Docker. 但不幸的是我的查询花费的时间比30s. 当失败时,错误是arangodb HTTPConnectionPool(host='127.0.0.1', port=8529): Read timed out. (read timeout=60)

  • 我的收藏大约有 4GB 大,大约有 1.2 mio - 收藏中有 900k 个文档。

我怎样才能获得包含所有文档的完整集合而不出现任何错误?

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 …

python arangodb docker docker-compose python-arango

3
推荐指数
1
解决办法
1296
查看次数