我有一个 Cosmos DB,需要使用 C# 查询 100 000 个单独的文档。这将填充一个网格(显然有分页)。我做了很多搜索,但似乎只找到了使用 FeedIterator 来查询数据。
目前我正在使用此代码来查询我的测试数据:
using (var appsIterator = _container.GetItemQueryIterator<SensorMaster>(query))
{
Console.WriteLine("\t\t\t\tID\tName\tUnitID\tPoints");
while (appsIterator.HasMoreResults)
{
var apps = await appsIterator.ReadNextAsync();
foreach (var item in apps)
{
count++;
Console.WriteLine($"{item.ID}\t{item.Name}\t{item.UnitID}\t{item.Points}");
}
charge += apps.RequestCharge;
}
Console.WriteLine($"Total charge: {charge}");
}
这会选择约 3900 条记录,但需要大约 45 秒才能完成。 有没有更好的方法来选择大量文档/记录?
最佳答案
对于非常大的查询(您想要对结果进行分页),请使用继续标记。您可以在这里获取更多信息并学习如何使用,Pagination in Azure Cosmos DB .
您要关注的是 MaxItemCount,而不是 MaxPageSize。
顺便说一句,向用户分页 100K 记录是一个奇怪的用例。我想我不记得有人想要滚动浏览 100K 项。
关于C# Azure Cosmos DB - 如何选择大量数据(~100,000 个文档),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72678650/