是否可以,使用 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/