azure - 是否可以异步查询 DocumentDB 的所有文档(即无分页)?

标签 azure azure-cosmosdb

是否可以,使用 DocumentDB .NET SDK ,对返回所有匹配文档的数据库运行异步查询?

此 StackOverflow 问题的答案:Querying Azure DocumentDB with ExecuteNextAsync returns fewer than MaxItemCount表明:

There are limits for how long a query will execute on DocumentDB.
...
If these limits are hit, then a partial set of results may be returned.

我知道可以通过迭代分页结果来克服上述限制,如下所示:( source )

List<Family> families = new List<Family>();

FeedOptions options = new FeedOptions { MaxItemCount = 1 };

var query = client.CreateDocumentQuery<Family>(collectionLink, options).AsDocumentQuery();

while (query.HasMoreResults)
{
    foreach (Family family in await query.ExecuteNextAsync())
    {
        families.Add(family);
    }
}

我的问题是 - 这个循环有必要吗?是否有一种更优雅的方式来告诉 SDK 返回所有可用结果(无需分页)?

最佳答案

您所拥有的循环是跨多个请求执行枚举的最佳方式,因为 DocumentDB 中的每个请求都有有限的执行时间。

您可以将此代码包装在扩展方法中以方便使用。

对于 DocumentDB 团队来说,添加此支持是一个很好的建议 - https://github.com/Azure/azure-documentdb-dotnet/issues

关于azure - 是否可以异步查询 DocumentDB 的所有文档(即无分页)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38570663/

相关文章:

c# - 在 documentDB 中按子字符串搜索

java - 插入文档时达到最大池大小时出现 ConnectionPoolTimeoutException

Azure Cosmos DB - Azure DocumentDB 数据迁移工具 - 无法将大型数据库 (4GB) 导出到 json 文件

azure - 有条件地设置环境 Azure DevOps

python - 找不到资源错误: When Reading CSV from Azure Blob using Pandas with its SAS URL

javascript - Cosmos DB Mongo API 如何管理 "Request Rate is Large"条件

excel - Azure机器学习工作室: how to add a dataset from a local Excel file?

azure - 无法激活 Application Insight(也无法激活实时流指标)

linux - Ubuntu 上 CosmosDB 的 CRT 证书不起作用

azure - 当请求超出预留 RU 时,Azure Cosmos Db 如何决定拒绝请求?