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

Is it possible to asynchronously query DocumentDB for all documents (i.e no paging)?

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

这个 Whosebug 问题的答案: 表示:

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 return 所有可用结果(无需分页)?

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

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

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