繁体   English   中英

读取集合中的所有文档时未找到 Cursor

[英]Cursor not found while reading all documents from a collection

我有一个收藏student ,我想要这个收藏作为 Python 中的list ,但不幸的是我收到以下错误CursorNextError: [HTTP 404][ERR 1600] cursor not found 是否可以选择无误地读取“庞大”的集合?

from arango import ArangoClient

# Initialize the ArangoDB client.
client = ArangoClient()

# Connect to database as  user.
db = client.db(<db>, username=<username>, password=<password>)

print(db.collections())
students = db.collection('students')
#students.all()

students = db.collection('handlingUnits').all()
list(students)
[OUT] CursorNextError: [HTTP 404][ERR 1600] cursor not found

students = list(db.collection('students'))
[OUT] CursorNextError: [HTTP 404][ERR 1600] cursor not found

正如我在评论中所建议的那样,如果提高 ttl 不是一个选项(我也不会这样做),我会分块而不是一次获取所有数据。 在大多数情况下,无论如何您都不需要整个集合,所以也许首先考虑限制它。 您真的需要所有文档及其所有字段吗? 那个蜜蜂说我没有使用 arango 的经验,但这就是我要做的:

entries = db.collection('students').count() # get total amount of documents in collection
limit=100 # blocksize you want to request
yourlist = [] # final output
for x in range(int(entries/limit) + 1):
    block = db.collection('students').all(skip=x*limit, limit=100)
    yourlist.extend(block) # assuming block is of type list. Not sure what arango returns

像这样的东西。 (基于此处的文档: https://python-driver-for-arangodb.readthedocs.io/_/downloads/en/dev/pdf/

将您的请求限制在一个合理的数量,然后在您的下一个请求中跳过这个数量。 您必须检查这个“range()”是否像您可能需要考虑定义所需迭代次数的更好方法那样工作。 这还假设 arango 默认对 all() function 进行排序。

那么这个想法是什么?

  1. 确定集合中的条目数。
  2. 基于这个决定你需要多少请求(fe size=1000 -> 10 blocks each containing 100 entries)
  3. 在跳过已有块的地方发出 x 请求。 第一次迭代条目 1-100; 第二次迭代 101-200,第三次迭代 201-300 等。

默认情况下,AQL 查询生成完整的结果,然后保存在 memory 中,并逐批提供。 所以 cursor 只是获取下一批已经计算的结果。 在大多数情况下这很好,但是如果您的查询产生一个巨大的结果集,那么这可能需要很长时间并且需要很多 memory。

作为替代方案,您可以创建流式传输 cursor 请参阅https://www.arangodb.com/docs/stable/http/aql-query-cursor-accessing-cursors.html并选中stream选项。 流式游标按需计算下一批,因此更适合迭代大型集合。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM